hoffmation-base 2.22.9 → 2.22.11

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.
@@ -41,4 +41,5 @@ export declare abstract class ZigbeeDimmer extends ZigbeeDevice implements iDimm
41
41
  setLight(pValue: boolean, timeout?: number, force?: boolean, brightness?: number, transitionTime?: number): void;
42
42
  persist(): void;
43
43
  toggleLight(time?: TimeOfDay, force?: boolean, calculateTime?: boolean): boolean;
44
+ private setBrightnessState;
44
45
  }
@@ -106,7 +106,7 @@ class ZigbeeDimmer extends index_1.ZigbeeDevice {
106
106
  if (sharedFunctions_1.LampUtils.checkBlockActive(this, force, pValue)) {
107
107
  return;
108
108
  }
109
- if (pValue && brightness === -1 && this.brightness < 10) {
109
+ if (pValue && brightness <= 0 && this.brightness < 10) {
110
110
  brightness = 10;
111
111
  }
112
112
  this.log(models_1.LogLevel.Debug, `Set Light Acutator to "${pValue}" with brightness ${brightness}`, services_1.LogDebugType.SetActuator);
@@ -120,13 +120,13 @@ class ZigbeeDimmer extends index_1.ZigbeeDevice {
120
120
  return;
121
121
  }
122
122
  if (brightness >= this.settings.turnOnThreshhold) {
123
- this.setState(this._stateIdBrightness, brightness);
123
+ this.setBrightnessState(brightness);
124
124
  return;
125
125
  }
126
- this.setState(this._stateIdBrightness, this.settings.turnOnThreshhold, () => {
126
+ this.setBrightnessState(this.settings.turnOnThreshhold, () => {
127
127
  services_1.Utils.guardedTimeout(() => {
128
128
  this.log(models_1.LogLevel.Info, `Delayed reduced brightness on ${this.info.customName}`);
129
- this.setState(this._stateIdBrightness, brightness);
129
+ this.setBrightnessState(brightness);
130
130
  }, 1000, this);
131
131
  });
132
132
  }
@@ -142,5 +142,8 @@ class ZigbeeDimmer extends index_1.ZigbeeDevice {
142
142
  toggleLight(time, force = false, calculateTime = false) {
143
143
  return sharedFunctions_1.LampUtils.toggleLight(this, time, force, calculateTime);
144
144
  }
145
+ setBrightnessState(brightness, onSuccess) {
146
+ this.setState(this._stateIdBrightness, Math.max(0, Math.min(brightness, 100)), onSuccess);
147
+ }
145
148
  }
146
149
  exports.ZigbeeDimmer = ZigbeeDimmer;
@@ -1,5 +1,5 @@
1
- import { Device as GoveeDevice } from 'theimo1221-govee-lan-control';
2
1
  import { OwnGoveeDevice } from './own-govee-device';
2
+ import { Device as GoveeDevice } from '@j3lte/govee-lan-controller';
3
3
  export declare class GooveeService {
4
4
  static all: GoveeDevice[];
5
5
  static devicesDict: {
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.GooveeService = void 0;
7
4
  const log_service_1 = require("../log-service");
8
5
  const models_1 = require("../../../models");
9
- const theimo1221_govee_lan_control_1 = __importDefault(require("theimo1221-govee-lan-control"));
6
+ const govee_lan_controller_1 = require("@j3lte/govee-lan-controller");
10
7
  class GooveeService {
11
8
  static addOwnDevices(gvDevice) {
12
9
  this.ownDevices = gvDevice;
@@ -14,40 +11,52 @@ class GooveeService {
14
11
  static initialize() {
15
12
  log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Initializing Goovee-Service`);
16
13
  this.all = [];
17
- this.goveeApi = new theimo1221_govee_lan_control_1.default({
18
- logger: (message) => {
19
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee: ${message}`);
20
- },
21
- errorLogger: (message) => {
22
- if (message.startsWith('UDP Socket was not')) {
23
- return;
24
- }
25
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Govee: ${message}`);
26
- },
27
- });
28
- this.goveeApi.on('deviceAdded', (device) => {
29
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `GoveeDevice ${device.deviceID} joined`);
14
+ this.goveeApi = new govee_lan_controller_1.Govee({
15
+ discover: true,
16
+ discoverInterval: 300000,
17
+ });
18
+ this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Scan, (data) => {
19
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `GoveeDevice ${data.ip} scanned`);
20
+ });
21
+ this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Ready, () => {
22
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Govee ready`);
23
+ });
24
+ this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Error, (err) => {
25
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Govee-Error: ${err}`);
26
+ });
27
+ this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.NewDevice, (device) => {
28
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `GoveeDevice ${device.id} joined`);
30
29
  GooveeService.initializeDevice(device);
31
30
  });
32
- this.goveeApi.on('updatedStatus', (device, data, _stateChanged) => {
33
- GooveeService.updateDevice(device, data);
31
+ this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.UnknownDevice, (_data) => {
32
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `GoveeDevice unknown`);
33
+ });
34
+ this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.UnknownMessage, (data) => {
35
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `GoveeDevice unknown message: ${data}`);
34
36
  });
37
+ this.goveeApi.discover();
35
38
  }
36
39
  static initializeDevice(d) {
37
- this.devicesDict[d.deviceID] = d;
38
- if (this.ownDevices[d.deviceID] === undefined) {
39
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${d.deviceID}"`);
40
+ this.devicesDict[d.id] = d;
41
+ if (this.ownDevices[d.id] === undefined) {
42
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${d.id}"`);
40
43
  return;
41
44
  }
42
- this.ownDevices[d.deviceID].device = d;
43
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.deviceID} found at address ${d.ip}`);
45
+ const ownDevice = this.ownDevices[d.id];
46
+ ownDevice.device = d;
47
+ ownDevice.update(d.getState());
48
+ d.on(govee_lan_controller_1.GoveeDeviceEventTypes.StateChange, (data) => {
49
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.id} state changed`);
50
+ this.updateDevice(d, data);
51
+ });
52
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.id} found at address ${d.ipAddr}`);
44
53
  }
45
54
  static updateDevice(device, data) {
46
- if (this.ownDevices[device.deviceID] === undefined) {
47
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${device.deviceID}"`);
55
+ if (this.ownDevices[device.id] === undefined) {
56
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${device.id}"`);
48
57
  return;
49
58
  }
50
- this.ownDevices[device.deviceID].update(data);
59
+ this.ownDevices[device.id].update(data);
51
60
  }
52
61
  }
53
62
  exports.GooveeService = GooveeService;
@@ -3,8 +3,9 @@ import { LedSettings, LogLevel, RoomBase, TimeOfDay } from '../../../models';
3
3
  import { LogDebugType } from '../log-service';
4
4
  import { DeviceCapability } from '../../devices/DeviceCapability';
5
5
  import { iLedRgbCct } from '../../devices/baseDeviceInterfaces/iLedRgbCct';
6
- import { Device as GoveeDevice, DeviceState as GoveeDeviceState } from 'theimo1221-govee-lan-control';
6
+ import { Device as GoveeDevice, DeviceStateInfo as GoveeDeviceStateInfo } from '@j3lte/govee-lan-controller';
7
7
  import { BlockAutomaticHandler } from '../blockAutomaticHandler';
8
+ import { DeviceState as GoveeDeviceState } from '@j3lte/govee-lan-controller/build/types/device';
8
9
  export declare class OwnGoveeDevice implements iLedRgbCct, iTemporaryDisableAutomatic {
9
10
  device: GoveeDevice | undefined;
10
11
  settings: LedSettings;
@@ -48,7 +49,7 @@ export declare class OwnGoveeDevice implements iLedRgbCct, iTemporaryDisableAuto
48
49
  persist(): void;
49
50
  toggleActuator(_force: boolean): boolean;
50
51
  toggleLight(time?: TimeOfDay, _force?: boolean, calculateTime?: boolean): boolean;
51
- update(data: GoveeDeviceState): void;
52
+ update(data: GoveeDeviceState & GoveeDeviceStateInfo): void;
52
53
  private setBrightness;
53
54
  private setColor;
54
55
  private turnOn;
@@ -176,14 +176,14 @@ class OwnGoveeDevice {
176
176
  }
177
177
  update(data) {
178
178
  this.queuedValue = null;
179
- this.on = data.isOn === 1;
179
+ this.on = data.onOff === 1;
180
180
  this.brightness = data.brightness;
181
181
  this._color = `#${data.color.r.toString(16)}${data.color.g.toString(16)}${data.color.b.toString(16)}`;
182
- this._colortemp = data.colorKelvin;
182
+ this._colortemp = data.colorTemInKelvin;
183
183
  }
184
184
  setBrightness(brightness, cb) {
185
185
  var _a;
186
- (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setBrightness(brightness).then(() => {
186
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.setBrightness(brightness).then(() => {
187
187
  cb();
188
188
  }).catch((error) => {
189
189
  this.log(models_1.LogLevel.Error, `Govee set brightness resulted in error: ${error}`);
@@ -194,7 +194,12 @@ class OwnGoveeDevice {
194
194
  if (color === this._color) {
195
195
  return;
196
196
  }
197
- (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setColor({ hex: color }).then(() => {
197
+ const colors = utils_1.Utils.hexToRgb(color);
198
+ if (colors === null) {
199
+ this.log(models_1.LogLevel.Error, `Govee set color resulted in error: ${color} is not a valid color`);
200
+ return;
201
+ }
202
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.setColorRGB(colors).then(() => {
198
203
  this.log(models_1.LogLevel.Debug, `Govee set color to ${color}`, log_service_1.LogDebugType.SetActuator);
199
204
  }).catch((error) => {
200
205
  this.log(models_1.LogLevel.Error, `Govee set color resulted in error: ${error}`);
@@ -206,7 +211,7 @@ class OwnGoveeDevice {
206
211
  return;
207
212
  }
208
213
  this.queuedValue = true;
209
- (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setOn().then(() => {
214
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.turnOn().then(() => {
210
215
  this.log(models_1.LogLevel.Debug, `Govee turned on`, log_service_1.LogDebugType.SetActuator);
211
216
  }).catch((error) => {
212
217
  this.log(models_1.LogLevel.Error, `Govee turn on resulted in error: ${error}`);
@@ -215,7 +220,7 @@ class OwnGoveeDevice {
215
220
  turnOff() {
216
221
  var _a;
217
222
  this.queuedValue = false;
218
- (_a = this.device) === null || _a === void 0 ? void 0 : _a.actions.setOff().then(() => {
223
+ (_a = this.device) === null || _a === void 0 ? void 0 : _a.turnOff().then(() => {
219
224
  this.log(models_1.LogLevel.Debug, `Govee turned off`, log_service_1.LogDebugType.SetActuator);
220
225
  }).catch((error) => {
221
226
  this.log(models_1.LogLevel.Error, `Govee turn off resulted in error: ${error}`);
@@ -34,4 +34,9 @@ export declare class Utils {
34
34
  static nextMatchingDate(hours?: number, minutes?: number, now?: Date): Date;
35
35
  static timeWithinBorders(minimumHours: number, minimumMinutes: number, maxHours: number, maxMinutes: number, now?: Date): boolean;
36
36
  static formatHex(hex: string): string | null;
37
+ static hexToRgb(color: string): {
38
+ r: number;
39
+ g: number;
40
+ b: number;
41
+ } | null;
37
42
  }
@@ -244,5 +244,26 @@ class Utils {
244
244
  }
245
245
  return hex;
246
246
  }
247
+ static hexToRgb(color) {
248
+ let hex = Utils.formatHex(color);
249
+ if (hex === null) {
250
+ return null;
251
+ }
252
+ const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
253
+ hex = hex.replace(shorthandRegex, (_m, r, g, b) => {
254
+ return r + r + g + g + b + b;
255
+ });
256
+ const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
257
+ if (!result || result.length !== 4) {
258
+ return null;
259
+ }
260
+ const r = parseInt(result[1], 16);
261
+ const g = parseInt(result[2], 16);
262
+ const b = parseInt(result[3], 16);
263
+ if (isNaN(r) || isNaN(g) || isNaN(b)) {
264
+ return null;
265
+ }
266
+ return { r, g, b };
267
+ }
247
268
  }
248
269
  exports.Utils = Utils;