hoffmation-base 2.19.7 → 2.20.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -19,6 +19,7 @@ const server_1 = require("./server");
19
19
  const models_1 = require("./models");
20
20
  const dachs_1 = require("./server/devices/dachs");
21
21
  require("@iobroker/types");
22
+ const govee_1 = require("./server/services/govee");
22
23
  __exportStar(require("./models/index"), exports);
23
24
  __exportStar(require("./server/index"), exports);
24
25
  __exportStar(require("./liquid-pid"), exports);
@@ -80,6 +81,10 @@ class HoffmationBase {
80
81
  server_1.SonosService.addOwnDevices(server_1.OwnSonosDevices.ownDevices);
81
82
  server_1.SonosService.initialize();
82
83
  }
84
+ if (server_1.SettingsService.settings.goveeDevicesPresent) {
85
+ govee_1.GooveeService.addOwnDevices(govee_1.OwnGoveeDevices.ownDevices);
86
+ govee_1.GooveeService.initialize();
87
+ }
83
88
  if ((_b = server_1.SettingsService.settings.daikin) === null || _b === void 0 ? void 0 : _b.active) {
84
89
  server_1.DaikinService.addOwnDevices(server_1.OwnAcDevices.ownDevices);
85
90
  server_1.DaikinService.initialize();
@@ -30,6 +30,7 @@ export interface iConfig {
30
30
  espresense?: iEspresenseSettings;
31
31
  ioBrokerUrl: string;
32
32
  ioBroker?: iIobrokerSettigns;
33
+ goveeDevicesPresent?: boolean;
33
34
  heaterSettings?: iHeaterSettings;
34
35
  logSettings?: iLogSettings;
35
36
  mp3Server?: iMp3Settings;
@@ -4,7 +4,6 @@ export interface iLedRgbCct extends iDimmableLamp {
4
4
  settings: LedSettings;
5
5
  readonly color: string;
6
6
  readonly colortemp: number;
7
- update(idSplit: string[], state: ioBroker.State, initial: boolean): void;
8
7
  /**
9
8
  * @inheritDoc
10
9
  */
@@ -81,6 +81,7 @@ class DeviceCluster {
81
81
  case deviceType_1.DeviceType.ZigbeeIlluLedRGBCCT:
82
82
  case deviceType_1.DeviceType.ZigbeeLinkindLedRgbCct:
83
83
  case deviceType_1.DeviceType.ZigbeeInnr142C:
84
+ case deviceType_1.DeviceType.GoveeLed:
84
85
  clusterTypes.push(device_cluster_type_1.DeviceClusterType.LED);
85
86
  break;
86
87
  case deviceType_1.DeviceType.ZigbeeAquaraVibra:
@@ -43,6 +43,7 @@ export declare enum DeviceType {
43
43
  ShellyTrv = 402,
44
44
  TuyaGarageDoorOpener = 501,
45
45
  WledDevice = 1001,
46
+ GoveeLed = 1002,
46
47
  Daikin = 2001,
47
48
  Sonos = 3001,
48
49
  Espresense = 4001,
@@ -47,6 +47,7 @@ var DeviceType;
47
47
  DeviceType[DeviceType["ShellyTrv"] = 402] = "ShellyTrv";
48
48
  DeviceType[DeviceType["TuyaGarageDoorOpener"] = 501] = "TuyaGarageDoorOpener";
49
49
  DeviceType[DeviceType["WledDevice"] = 1001] = "WledDevice";
50
+ DeviceType[DeviceType["GoveeLed"] = 1002] = "GoveeLed";
50
51
  DeviceType[DeviceType["Daikin"] = 2001] = "Daikin";
51
52
  DeviceType[DeviceType["Sonos"] = 3001] = "Sonos";
52
53
  DeviceType[DeviceType["Espresense"] = 4001] = "Espresense";
@@ -0,0 +1,16 @@
1
+ import { Device as GoveeDevice } from 'theimo1221-govee-lan-control';
2
+ import { OwnGoveeDevice } from './own-govee-device';
3
+ export declare class GooveeService {
4
+ static all: GoveeDevice[];
5
+ static devicesDict: {
6
+ [name: string]: GoveeDevice;
7
+ };
8
+ private static goveeApi;
9
+ private static ownDevices;
10
+ static addOwnDevices(gvDevice: {
11
+ [name: string]: OwnGoveeDevice;
12
+ }): void;
13
+ static initialize(): void;
14
+ private static initializeDevice;
15
+ private static updateDevice;
16
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GooveeService = void 0;
7
+ const log_service_1 = require("../log-service");
8
+ const models_1 = require("../../../models");
9
+ const theimo1221_govee_lan_control_1 = __importDefault(require("theimo1221-govee-lan-control"));
10
+ class GooveeService {
11
+ static addOwnDevices(gvDevice) {
12
+ this.ownDevices = gvDevice;
13
+ }
14
+ static initialize() {
15
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Initializing Goovee-Service`);
16
+ this.all = [];
17
+ this.goveeApi = new theimo1221_govee_lan_control_1.default();
18
+ this.goveeApi.on('deviceAdded', (device) => {
19
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `GoveeDevice ${device.deviceID} joined`);
20
+ GooveeService.initializeDevice(device);
21
+ });
22
+ this.goveeApi.on('updatedStatus', (device, data, _stateChanged) => {
23
+ GooveeService.updateDevice(device, data);
24
+ });
25
+ }
26
+ static initializeDevice(d) {
27
+ this.devicesDict[d.deviceID] = d;
28
+ if (this.ownDevices[d.deviceID] === undefined) {
29
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${d.deviceID}"`);
30
+ return;
31
+ }
32
+ this.ownDevices[d.deviceID].device = d;
33
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.deviceID} found at address ${d.ip}`);
34
+ }
35
+ static updateDevice(device, data) {
36
+ if (this.ownDevices[device.deviceID] === undefined) {
37
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${device.deviceID}"`);
38
+ return;
39
+ }
40
+ this.ownDevices[device.deviceID].update(data);
41
+ }
42
+ }
43
+ exports.GooveeService = GooveeService;
44
+ GooveeService.all = [];
45
+ GooveeService.devicesDict = {};
46
+ GooveeService.ownDevices = {};
@@ -0,0 +1,3 @@
1
+ export * from './govee-service';
2
+ export * from './own-govee-device';
3
+ export * from './own-govee-devices';
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./govee-service"), exports);
18
+ __exportStar(require("./own-govee-device"), exports);
19
+ __exportStar(require("./own-govee-devices"), exports);
@@ -0,0 +1,55 @@
1
+ import { DeviceInfo, DeviceType, iTemporaryDisableAutomatic } from '../../devices';
2
+ import { LedSettings, LogLevel, RoomBase, TimeOfDay } from '../../../models';
3
+ import { LogDebugType } from '../log-service';
4
+ import { DeviceCapability } from '../../devices/DeviceCapability';
5
+ import { iLedRgbCct } from '../../devices/baseDeviceInterfaces/iLedRgbCct';
6
+ import { Device as GoveeDevice, DeviceState as GoveeDeviceState } from 'theimo1221-govee-lan-control';
7
+ import { BlockAutomaticHandler } from '../blockAutomaticHandler';
8
+ export declare class OwnGoveeDevice implements iLedRgbCct, iTemporaryDisableAutomatic {
9
+ device: GoveeDevice | undefined;
10
+ settings: LedSettings;
11
+ readonly deviceType: DeviceType;
12
+ readonly deviceId: string;
13
+ readonly deviceCapabilities: DeviceCapability[];
14
+ readonly blockAutomationHandler: BlockAutomaticHandler;
15
+ on: boolean;
16
+ brightness: number;
17
+ constructor(deviceId: string, ownDeviceName: string, roomName: string, device: GoveeDevice | undefined);
18
+ private _color;
19
+ private _colortemp;
20
+ private _targetAutomaticState;
21
+ private _room;
22
+ get color(): string;
23
+ get colortemp(): number;
24
+ get customName(): string;
25
+ get actuatorOn(): boolean;
26
+ get lightOn(): boolean;
27
+ protected _info: DeviceInfo;
28
+ get info(): DeviceInfo;
29
+ set info(info: DeviceInfo);
30
+ get room(): RoomBase;
31
+ get id(): string;
32
+ get name(): string;
33
+ log(level: LogLevel, message: string, debugType?: LogDebugType): void;
34
+ toJSON(): Partial<OwnGoveeDevice>;
35
+ persistDeviceInfo(): void;
36
+ loadDeviceSettings(): void;
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ setTimeBased(time: TimeOfDay, timeout?: number, force?: boolean): void;
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ setLight(pValue: boolean, timeout?: number, force?: boolean, brightness?: number, _transitionTime?: number, color?: string, colorTemp?: number): void;
45
+ setActuator(pValue: boolean, timeout?: number, force?: boolean): void;
46
+ restoreTargetAutomaticValue(): void;
47
+ private setBrightness;
48
+ private setColor;
49
+ private turnOn;
50
+ private turnOff;
51
+ persist(): void;
52
+ toggleActuator(_force: boolean): boolean;
53
+ toggleLight(time?: TimeOfDay, _force?: boolean, calculateTime?: boolean): boolean;
54
+ update(data: GoveeDeviceState): void;
55
+ }
@@ -0,0 +1,244 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OwnGoveeDevice = void 0;
7
+ const devices_1 = require("../../devices");
8
+ const models_1 = require("../../../models");
9
+ const log_service_1 = require("../log-service");
10
+ const utils_1 = require("../utils");
11
+ const lodash_1 = __importDefault(require("lodash"));
12
+ const DeviceCapability_1 = require("../../devices/DeviceCapability");
13
+ const api_1 = require("../api");
14
+ const blockAutomaticHandler_1 = require("../blockAutomaticHandler");
15
+ const time_callback_service_1 = require("../time-callback-service");
16
+ class OwnGoveeDevice {
17
+ constructor(deviceId, ownDeviceName, roomName, device) {
18
+ this.device = device;
19
+ this.settings = new models_1.LedSettings();
20
+ this.deviceType = devices_1.DeviceType.GoveeLed;
21
+ this.deviceCapabilities = [
22
+ DeviceCapability_1.DeviceCapability.lamp,
23
+ DeviceCapability_1.DeviceCapability.dimmablelamp,
24
+ DeviceCapability_1.DeviceCapability.blockAutomatic,
25
+ ];
26
+ this.on = false;
27
+ this.brightness = -1;
28
+ this._color = '#fcba32';
29
+ this._colortemp = 500;
30
+ this._targetAutomaticState = false;
31
+ this._room = undefined;
32
+ this.deviceId = deviceId;
33
+ this._info = new devices_1.DeviceInfo();
34
+ this._info.fullName = `Govee ${roomName} ${ownDeviceName}`;
35
+ this._info.customName = `Govee ${ownDeviceName}`;
36
+ this._info.room = roomName;
37
+ this._info.allDevicesKey = `govee-${roomName}-${deviceId}`;
38
+ devices_1.Devices.alLDevices[`govee-${roomName}-${deviceId}`] = this;
39
+ this.persistDeviceInfo();
40
+ this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this));
41
+ this.loadDeviceSettings();
42
+ }
43
+ get color() {
44
+ return this._color;
45
+ }
46
+ get colortemp() {
47
+ return this._colortemp;
48
+ }
49
+ get customName() {
50
+ return this.info.customName;
51
+ }
52
+ get actuatorOn() {
53
+ return this.on;
54
+ }
55
+ get lightOn() {
56
+ return this.on;
57
+ }
58
+ get info() {
59
+ return this._info;
60
+ }
61
+ set info(info) {
62
+ this._info = info;
63
+ }
64
+ get room() {
65
+ if (this._room === undefined) {
66
+ this._room = utils_1.Utils.guard(api_1.API.getRoom(this.info.room));
67
+ }
68
+ return this._room;
69
+ }
70
+ get id() {
71
+ var _a;
72
+ return (_a = this.info.allDevicesKey) !== null && _a !== void 0 ? _a : `govee-${this.info.room}-${this.info.customName}`;
73
+ }
74
+ get name() {
75
+ return this.info.customName;
76
+ }
77
+ log(level, message, debugType = log_service_1.LogDebugType.None) {
78
+ var _a, _b;
79
+ log_service_1.ServerLogService.writeLog(level, `${this.name}: ${message}`, {
80
+ debugType: debugType,
81
+ room: (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.roomName) !== null && _b !== void 0 ? _b : '',
82
+ deviceId: this.name,
83
+ deviceName: this.name,
84
+ });
85
+ }
86
+ toJSON() {
87
+ return utils_1.Utils.jsonFilter(lodash_1.default.omit(this, ['room']));
88
+ }
89
+ persistDeviceInfo() {
90
+ utils_1.Utils.guardedTimeout(() => {
91
+ var _a;
92
+ (_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
93
+ }, 5000, this);
94
+ }
95
+ loadDeviceSettings() {
96
+ this.settings.initializeFromDb(this);
97
+ }
98
+ /**
99
+ * @inheritDoc
100
+ */
101
+ setTimeBased(time, timeout = -1, force = false) {
102
+ switch (time) {
103
+ case models_1.TimeOfDay.Night:
104
+ if (this.settings.nightOn) {
105
+ this.setLight(true, timeout, force, this.settings.nightBrightness, undefined, this.settings.nightColor, this.settings.nightColorTemp);
106
+ }
107
+ break;
108
+ case models_1.TimeOfDay.AfterSunset:
109
+ if (this.settings.duskOn) {
110
+ this.setLight(true, timeout, force, this.settings.duskBrightness, undefined, this.settings.duskColor, this.settings.duskColorTemp);
111
+ }
112
+ break;
113
+ case models_1.TimeOfDay.BeforeSunrise:
114
+ if (this.settings.dawnOn) {
115
+ this.setLight(true, timeout, force, this.settings.dawnBrightness, undefined, this.settings.dawnColor, this.settings.dawnColorTemp);
116
+ }
117
+ break;
118
+ case models_1.TimeOfDay.Daylight:
119
+ if (this.settings.dayOn) {
120
+ this.setLight(true, timeout, force, this.settings.dayBrightness, undefined, this.settings.dayColor, this.settings.dayColorTemp);
121
+ }
122
+ break;
123
+ }
124
+ }
125
+ /**
126
+ * @inheritDoc
127
+ */
128
+ setLight(pValue, timeout = -1, force, brightness = -1, _transitionTime, color = '', colorTemp = -1) {
129
+ var _a;
130
+ if (pValue && brightness === -1 && this.brightness < 10) {
131
+ brightness = 10;
132
+ }
133
+ this.log(models_1.LogLevel.Debug, `LED Schalten An: ${pValue}\tHelligkeit: ${brightness}%\tFarbe: "${color}"\tColorTemperatur: ${colorTemp}`);
134
+ if (color !== '') {
135
+ this.setColor(color);
136
+ }
137
+ let dontBlock = false;
138
+ if (force &&
139
+ this.settings.resetToAutomaticOnForceOffAfterForceOn &&
140
+ !pValue &&
141
+ this.blockAutomationHandler.automaticBlockActive) {
142
+ dontBlock = true;
143
+ this.log(models_1.LogLevel.Debug, `Reset Automatic Block as we are turning off manually after a force on`);
144
+ this.blockAutomationHandler.liftAutomaticBlock();
145
+ }
146
+ if (!force && this.blockAutomationHandler.automaticBlockActive) {
147
+ this.log(models_1.LogLevel.Debug, `Skip automatic command to ${pValue} as it is locked until ${new Date(this.blockAutomationHandler.automaticBlockedUntil).toLocaleTimeString()}`);
148
+ this._targetAutomaticState = pValue;
149
+ return;
150
+ }
151
+ this.log(models_1.LogLevel.Debug, `Set Light Acutator to "${pValue}" with brightness ${brightness}`, log_service_1.LogDebugType.SetActuator);
152
+ if (brightness > -1 && pValue) {
153
+ this.setBrightness(brightness, () => {
154
+ this.log(models_1.LogLevel.Debug, `Brightness set to ${brightness}`);
155
+ this.turnOn();
156
+ });
157
+ }
158
+ else if (pValue) {
159
+ this.turnOn();
160
+ }
161
+ else {
162
+ this.turnOff();
163
+ }
164
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setOn();
165
+ if (timeout > -1 && !dontBlock) {
166
+ this.blockAutomationHandler.disableAutomatic(timeout, models_1.CollisionSolving.overrideIfGreater);
167
+ }
168
+ }
169
+ setActuator(pValue, timeout, force) {
170
+ this.setLight(pValue, timeout, force);
171
+ }
172
+ restoreTargetAutomaticValue() {
173
+ this.log(models_1.LogLevel.Debug, `Restore Target Automatic value`);
174
+ this.setActuator(this._targetAutomaticState);
175
+ }
176
+ setBrightness(brightness, cb) {
177
+ var _a;
178
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setBrightness(brightness).then(() => {
179
+ cb();
180
+ }).catch((error) => {
181
+ this.log(models_1.LogLevel.Error, `Govee set brightness resulted in error: ${error}`);
182
+ });
183
+ }
184
+ setColor(color) {
185
+ var _a;
186
+ if (color === this._color) {
187
+ return;
188
+ }
189
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setColor({ hex: color }).then(() => {
190
+ this.log(models_1.LogLevel.Debug, `Govee set color to ${color}`, log_service_1.LogDebugType.SetActuator);
191
+ }).catch((error) => {
192
+ this.log(models_1.LogLevel.Error, `Govee set color resulted in error: ${error}`);
193
+ });
194
+ }
195
+ turnOn() {
196
+ var _a;
197
+ if (this.on) {
198
+ return;
199
+ }
200
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setOn().then(() => {
201
+ this.log(models_1.LogLevel.Debug, `Govee turned on`, log_service_1.LogDebugType.SetActuator);
202
+ }).catch((error) => {
203
+ this.log(models_1.LogLevel.Error, `Govee turn on resulted in error: ${error}`);
204
+ });
205
+ }
206
+ turnOff() {
207
+ var _a;
208
+ if (!this.on) {
209
+ return;
210
+ }
211
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setOff().then(() => {
212
+ this.log(models_1.LogLevel.Debug, `Govee turned off`, log_service_1.LogDebugType.SetActuator);
213
+ }).catch((error) => {
214
+ this.log(models_1.LogLevel.Error, `Govee turn off resulted in error: ${error}`);
215
+ });
216
+ }
217
+ persist() {
218
+ var _a;
219
+ (_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistActuator(this);
220
+ }
221
+ toggleActuator(_force) {
222
+ this.setLight(!this.on);
223
+ return this.on;
224
+ }
225
+ toggleLight(time, _force = false, calculateTime = false) {
226
+ const newVal = !this.lightOn;
227
+ if (newVal && time === undefined && calculateTime) {
228
+ time = time_callback_service_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
229
+ }
230
+ if (newVal && time !== undefined) {
231
+ this.setTimeBased(time);
232
+ return true;
233
+ }
234
+ this.setLight(newVal);
235
+ return newVal;
236
+ }
237
+ update(data) {
238
+ this.on = data.isOn === 1;
239
+ this.brightness = data.brightness;
240
+ this._color = `#${data.color.r.toString(16)}${data.color.g.toString(16)}${data.color.b.toString(16)}`;
241
+ this._colortemp = data.colorKelvin;
242
+ }
243
+ }
244
+ exports.OwnGoveeDevice = OwnGoveeDevice;
@@ -0,0 +1,7 @@
1
+ import { OwnGoveeDevice } from './own-govee-device';
2
+ export declare class OwnGoveeDevices {
3
+ static ownDevices: {
4
+ [name: string]: OwnGoveeDevice;
5
+ };
6
+ static addDevice(device: OwnGoveeDevice): void;
7
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OwnGoveeDevices = void 0;
4
+ const log_service_1 = require("../log-service");
5
+ const models_1 = require("../../../models");
6
+ class OwnGoveeDevices {
7
+ static addDevice(device) {
8
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Device ${device.name} for room "${device.info.room}" addded`);
9
+ this.ownDevices[device.deviceId] = device;
10
+ }
11
+ }
12
+ exports.OwnGoveeDevices = OwnGoveeDevices;
13
+ OwnGoveeDevices.ownDevices = {};