UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

101 lines 3.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDeviceModel = exports.IoTDevice = exports.WiFiDevice = exports.BLEDevice = exports.DeviceModel = exports.ProductModel = void 0; const common_1 = require("@nestjs/common"); const rxjs_1 = require("rxjs"); const version_info_1 = require("./version.info"); class ProductModel { constructor(category, group, modelName, ic, goodsType) { this.category = category; this.group = group; this.modelName = modelName; this.ic = ic; this.goodsType = goodsType; } } exports.ProductModel = ProductModel; class DeviceModel { constructor(args) { this.status = new rxjs_1.BehaviorSubject(args); this.id = args.id; this.name = args.name; this.model = args.model; this.modelName = args.modelName; this.iotTopic = args.iotTopic; this.ic = args.ic; this.goodsType = args.goodsType; this.pactCode = args.pactCode; this.pactType = args.pactType; this.version = args.version; this.category = args.category; this.categoryGroup = args.categoryGroup; this.images = args.deviceExt?.externalResources; } get productData() { return this.product; } set productData(product) { this.product = product; } } exports.DeviceModel = DeviceModel; const BLEDevice = (device) => { class BLEDeviceMixin extends device { constructor(...args) { super(args[0]); this.bleAddress = args[0].bleAddress; this.bleName = args[0].bleName; } } return BLEDeviceMixin; }; exports.BLEDevice = BLEDevice; const WiFiDevice = (device) => { class WiFiDeviceMixin extends device { constructor(...args) { super(args[0]); this.wifiAddress = args[0].wifiAddress; this.wifiSSID = args[0].wifiName; } } return WiFiDeviceMixin; }; exports.WiFiDevice = WiFiDevice; const IoTDevice = (device) => { class IoTDeviceMixin extends device { constructor(...args) { super(args[0]); this.iotTopic = args[0].iotTopic; } } return IoTDeviceMixin; }; exports.IoTDevice = IoTDevice; const createDeviceModel = (device, productCategories) => { let constructor = DeviceModel; if (device.blueTooth) { constructor = (0, exports.BLEDevice)(constructor); } if (device.wifi) { constructor = (0, exports.WiFiDevice)(constructor); } if (device.iotTopic) { constructor = (0, exports.IoTDevice)(constructor); } const product = productCategories[device.model]; if (!product) { new common_1.Logger('CreateDevice').log(`No product info for ${device.model}`); } const newDevice = new constructor({ ...device, version: new version_info_1.Version(device.hardwareVersion, device.softwareVersion), category: product?.category || 'unknown', categoryGroup: product?.group || 'unknown', modelName: product?.modelName || 'unknown', bleAddress: device.blueTooth?.mac, bleName: device.blueTooth?.name, }); return newDevice; }; exports.createDeviceModel = createDeviceModel; //# sourceMappingURL=devices.model.js.map