UNPKG

@constructorfleet/ultimate-govee

Version:

Library for interacting with Govee devices written in Typescript.

78 lines 3.94 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var DevicesFactory_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.DevicesFactory = void 0; const common_1 = require("@nestjs/common"); const cqrs_1 = require("@nestjs/cqrs"); const appliances_factory_1 = require("./impl/appliances/appliances.factory"); const lights_factory_1 = require("./impl/lights/lights.factory"); const device_1 = require("./device"); const home_improvement_1 = require("./impl/home-improvement"); const states_1 = require("./states"); const tv_factory_1 = require("./impl/tv/tv.factory"); const defaultStateFactories = [ (device) => new states_1.ActiveState(device), (device) => new states_1.BatteryLevelState(device), (device) => new states_1.BrightnessState(device), (device) => new states_1.ColorRGBState(device), (device) => new states_1.ColorTempState(device), (device) => new states_1.ConnectedState(device), (device) => new states_1.ControlLockState(device, 0x0aa, 0x0a), (device) => new states_1.DisplayScheduleState(device, 0x0aa, 0x12), (device) => new states_1.FilterLifeState(device, 0xaa, 0x19), (device) => new states_1.FilterExpiredState(device), (device) => new states_1.HumidityState(device), (device) => new states_1.LightEffectState(device), (device) => new states_1.ModeState(device, []), (device) => new states_1.NightLightState(device, 0xaa, 0x12), (device) => new states_1.PowerState(device), (device) => new states_1.TemperatureState(device), (device) => new states_1.TimerState(device, 0xaa, 0x0b), (device) => new states_1.WaterShortageState(device), ]; let DevicesFactory = DevicesFactory_1 = class DevicesFactory { constructor(applianceFactory, lightFactory, homeImprovementFactory, tvFactory, eventBus, commandBus) { this.applianceFactory = applianceFactory; this.lightFactory = lightFactory; this.homeImprovementFactory = homeImprovementFactory; this.tvFactory = tvFactory; this.eventBus = eventBus; this.commandBus = commandBus; this.logger = new common_1.Logger(DevicesFactory_1.name); } create(device) { const knownDevice = [ this.applianceFactory, this.lightFactory, this.homeImprovementFactory, this.tvFactory, ] .map((factory) => factory.create(device)) .find((d) => d !== undefined); if (knownDevice !== undefined) { return knownDevice; } this.logger.log(`Unable to determine device type for ${device.model} ${device.category} ${device.modelName}`); return new device_1.Device(device, this.eventBus, this.commandBus, defaultStateFactories); } }; exports.DevicesFactory = DevicesFactory; exports.DevicesFactory = DevicesFactory = DevicesFactory_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [appliances_factory_1.AppliancesFactory, lights_factory_1.LightsFactory, home_improvement_1.HomeImprovementFactory, tv_factory_1.TVFactory, cqrs_1.EventBus, cqrs_1.CommandBus]) ], DevicesFactory); //# sourceMappingURL=devices.factory.js.map