hoffmation-base 2.22.9 → 2.22.10
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/server/services/govee/govee-service.d.ts +1 -1
- package/lib/server/services/govee/govee-service.js +26 -27
- package/lib/server/services/govee/own-govee-device.d.ts +3 -2
- package/lib/server/services/govee/own-govee-device.js +11 -6
- package/lib/server/services/utils/utils.d.ts +5 -0
- package/lib/server/services/utils/utils.js +21 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -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
|
|
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,42 @@ 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
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
},
|
|
14
|
+
this.goveeApi = new govee_lan_controller_1.Govee({
|
|
15
|
+
discover: true,
|
|
16
|
+
discoverInterval: 300000,
|
|
27
17
|
});
|
|
28
|
-
this.goveeApi.on(
|
|
29
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `
|
|
30
|
-
|
|
18
|
+
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Ready, () => {
|
|
19
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Govee ready`);
|
|
20
|
+
});
|
|
21
|
+
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Error, (err) => {
|
|
22
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Govee-Error: ${err}`);
|
|
31
23
|
});
|
|
32
|
-
this.goveeApi.on(
|
|
33
|
-
|
|
24
|
+
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.NewDevice, (device) => {
|
|
25
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `GoveeDevice ${device.id} joined`);
|
|
26
|
+
GooveeService.initializeDevice(device);
|
|
34
27
|
});
|
|
35
28
|
}
|
|
36
29
|
static initializeDevice(d) {
|
|
37
|
-
this.devicesDict[d.
|
|
38
|
-
if (this.ownDevices[d.
|
|
39
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${d.
|
|
30
|
+
this.devicesDict[d.id] = d;
|
|
31
|
+
if (this.ownDevices[d.id] === undefined) {
|
|
32
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${d.id}"`);
|
|
40
33
|
return;
|
|
41
34
|
}
|
|
42
|
-
this.ownDevices[d.
|
|
43
|
-
|
|
35
|
+
const ownDevice = this.ownDevices[d.id];
|
|
36
|
+
ownDevice.device = d;
|
|
37
|
+
ownDevice.update(d.getState());
|
|
38
|
+
d.on(govee_lan_controller_1.GoveeDeviceEventTypes.StateChange, (data) => {
|
|
39
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.id} state changed`);
|
|
40
|
+
this.updateDevice(d, data);
|
|
41
|
+
});
|
|
42
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.id} found at address ${d.ipAddr}`);
|
|
44
43
|
}
|
|
45
44
|
static updateDevice(device, data) {
|
|
46
|
-
if (this.ownDevices[device.
|
|
47
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${device.
|
|
45
|
+
if (this.ownDevices[device.id] === undefined) {
|
|
46
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Unknown Govee Device "${device.id}"`);
|
|
48
47
|
return;
|
|
49
48
|
}
|
|
50
|
-
this.ownDevices[device.
|
|
49
|
+
this.ownDevices[device.id].update(data);
|
|
51
50
|
}
|
|
52
51
|
}
|
|
53
52
|
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,
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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;
|