hoffmation-base 2.22.8 → 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/api/api-service.js +20 -0
- 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 +7 -7
|
@@ -23,6 +23,7 @@ class API {
|
|
|
23
23
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.scene)) {
|
|
24
24
|
return new Error(`Device with ID ${deviceId} is no scene`);
|
|
25
25
|
}
|
|
26
|
+
d.log(models_1.LogLevel.Info, `API Call to end this.`);
|
|
26
27
|
d.endScene();
|
|
27
28
|
return null;
|
|
28
29
|
}
|
|
@@ -92,6 +93,7 @@ class API {
|
|
|
92
93
|
desiredMode = settings_service_1.SettingsService.heatMode == config_1.HeatingMode.Winter ? ac_1.AcMode.Heating : ac_1.AcMode.Cooling;
|
|
93
94
|
}
|
|
94
95
|
}
|
|
96
|
+
d.log(models_1.LogLevel.Info, `API Call to set AC to ${desiredState} with mode ${desiredMode} for ${forceTime}ms`);
|
|
95
97
|
d.setState(desiredMode, desiredTemperature, forceTime);
|
|
96
98
|
return true;
|
|
97
99
|
}
|
|
@@ -101,6 +103,7 @@ class API {
|
|
|
101
103
|
*/
|
|
102
104
|
static setAllAc(desiredState) {
|
|
103
105
|
ac_1.DaikinService.setAll(desiredState, true);
|
|
106
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `API Call to set all AC´s to ${desiredState}`);
|
|
104
107
|
}
|
|
105
108
|
/**
|
|
106
109
|
* Changes the status of a given Lamp
|
|
@@ -117,6 +120,7 @@ class API {
|
|
|
117
120
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.lamp)) {
|
|
118
121
|
return new Error(`Device with ID ${deviceId} is no Lamp`);
|
|
119
122
|
}
|
|
123
|
+
d.log(models_1.LogLevel.Info, `API Call to set Lamp to ${state} for ${timeout}ms`);
|
|
120
124
|
d.setLight(state, timeout, true);
|
|
121
125
|
return null;
|
|
122
126
|
}
|
|
@@ -135,6 +139,7 @@ class API {
|
|
|
135
139
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.actuator)) {
|
|
136
140
|
return new Error(`Device with ID ${deviceId} is no actuator`);
|
|
137
141
|
}
|
|
142
|
+
d.log(models_1.LogLevel.Info, `API Call to set Actuator to ${state} for ${timeout}ms`);
|
|
138
143
|
d.setActuator(state, timeout, true);
|
|
139
144
|
return null;
|
|
140
145
|
}
|
|
@@ -155,6 +160,7 @@ class API {
|
|
|
155
160
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.dimmablelamp)) {
|
|
156
161
|
return new Error(`Device with ID ${deviceId} is no dimmablelamp`);
|
|
157
162
|
}
|
|
163
|
+
d.log(models_1.LogLevel.Info, `API Call to set Dimmer to ${state} with brightness ${brightness} for ${timeout}ms`);
|
|
158
164
|
d.setLight(state, timeout, true, brightness, transitionTime);
|
|
159
165
|
return null;
|
|
160
166
|
}
|
|
@@ -177,6 +183,7 @@ class API {
|
|
|
177
183
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.ledLamp)) {
|
|
178
184
|
return new Error(`Device with ID ${deviceId} is no dimmablelamp`);
|
|
179
185
|
}
|
|
186
|
+
d.log(models_1.LogLevel.Info, `API Call to set LED to ${state} with brightness ${brightness} and color ${color} for ${timeout}ms`);
|
|
180
187
|
d.setLight(state, timeout, true, brightness, transitionTime, color, colorTemp);
|
|
181
188
|
return null;
|
|
182
189
|
}
|
|
@@ -202,6 +209,7 @@ class API {
|
|
|
202
209
|
else {
|
|
203
210
|
d.setLevel(level, false);
|
|
204
211
|
}
|
|
212
|
+
d.log(models_1.LogLevel.Info, `API Call to set Shutter to ${level}`);
|
|
205
213
|
return null;
|
|
206
214
|
}
|
|
207
215
|
static speakOnDevice(deviceId, message, volume = 30) {
|
|
@@ -212,6 +220,7 @@ class API {
|
|
|
212
220
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.speaker)) {
|
|
213
221
|
return new Error(`Device with ID ${deviceId} is no speaker`);
|
|
214
222
|
}
|
|
223
|
+
d.log(models_1.LogLevel.Info, `API Call to speak "${message}" on device with volume ${volume}`);
|
|
215
224
|
d.speakOnDevice(message, volume);
|
|
216
225
|
return null;
|
|
217
226
|
}
|
|
@@ -229,6 +238,7 @@ class API {
|
|
|
229
238
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.scene)) {
|
|
230
239
|
return new Error(`Device with ID ${deviceId} is no scene`);
|
|
231
240
|
}
|
|
241
|
+
d.log(models_1.LogLevel.Info, `API Call to start this.`);
|
|
232
242
|
d.startScene(turnOffTimeout);
|
|
233
243
|
return null;
|
|
234
244
|
}
|
|
@@ -241,9 +251,11 @@ class API {
|
|
|
241
251
|
return new Error(`Device with ID ${deviceId} is no Garage Door Opener`);
|
|
242
252
|
}
|
|
243
253
|
if (open) {
|
|
254
|
+
d.log(models_1.LogLevel.Info, `API Call to open Garage Door`);
|
|
244
255
|
d.open();
|
|
245
256
|
}
|
|
246
257
|
else {
|
|
258
|
+
d.log(models_1.LogLevel.Info, `API Call to close Garage Door`);
|
|
247
259
|
d.close();
|
|
248
260
|
}
|
|
249
261
|
return null;
|
|
@@ -262,6 +274,7 @@ class API {
|
|
|
262
274
|
if (d.settings === undefined) {
|
|
263
275
|
return new Error(`Device with ID ${deviceId} has no settings`);
|
|
264
276
|
}
|
|
277
|
+
d.log(models_1.LogLevel.Info, `API Call to change settings to ${JSON.stringify(settings)})}`);
|
|
265
278
|
d.settings.fromPartialObject(settings);
|
|
266
279
|
d.settings.persist(d);
|
|
267
280
|
return null;
|
|
@@ -274,6 +287,7 @@ class API {
|
|
|
274
287
|
if (g.settings === undefined) {
|
|
275
288
|
return new Error(`Group with ID ${groupId} has no settings`);
|
|
276
289
|
}
|
|
290
|
+
g.log(models_1.LogLevel.Info, `API Call to change settings to ${JSON.stringify(settings)})}`);
|
|
277
291
|
g.settings.fromPartialObject(settings);
|
|
278
292
|
g.settings.persist(g);
|
|
279
293
|
return null;
|
|
@@ -289,6 +303,7 @@ class API {
|
|
|
289
303
|
if (r === undefined) {
|
|
290
304
|
return new Error(`Room with ID ${roomName} not found`);
|
|
291
305
|
}
|
|
306
|
+
r.log(models_1.LogLevel.Info, `API Call to change settings to ${JSON.stringify(settings)})}`);
|
|
292
307
|
r.settings.settingsContainer.fromPartialObject(settings);
|
|
293
308
|
r.settings.settingsContainer.persist(r);
|
|
294
309
|
return null;
|
|
@@ -305,11 +320,13 @@ class API {
|
|
|
305
320
|
}
|
|
306
321
|
static persistAllDeviceSettings() {
|
|
307
322
|
var _a;
|
|
323
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `API Call to persist all device settings`);
|
|
308
324
|
for (const device of Object.values(devices_1.Devices.alLDevices)) {
|
|
309
325
|
(_a = device.settings) === null || _a === void 0 ? void 0 : _a.persist(device);
|
|
310
326
|
}
|
|
311
327
|
}
|
|
312
328
|
static loadAllDeviceSettingsFromDb() {
|
|
329
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `API Call to load all device settings`);
|
|
313
330
|
for (const device of Object.values(devices_1.Devices.alLDevices)) {
|
|
314
331
|
device.loadDeviceSettings();
|
|
315
332
|
}
|
|
@@ -327,6 +344,7 @@ class API {
|
|
|
327
344
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.blockAutomatic)) {
|
|
328
345
|
return new Error(`Device with ID ${deviceId} is not capable of blocking automatic`);
|
|
329
346
|
}
|
|
347
|
+
d.log(models_1.LogLevel.Info, `API Call to lift automatic block`);
|
|
330
348
|
d.blockAutomationHandler.liftAutomaticBlock();
|
|
331
349
|
return null;
|
|
332
350
|
}
|
|
@@ -345,6 +363,7 @@ class API {
|
|
|
345
363
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.blockAutomatic)) {
|
|
346
364
|
return new Error(`Device with ID ${deviceId} is not capable of blocking automatic`);
|
|
347
365
|
}
|
|
366
|
+
d.log(models_1.LogLevel.Info, `API Call to block automatic for ${duration}ms with ${onCollision} on collision`);
|
|
348
367
|
d.blockAutomationHandler.disableAutomatic(duration, onCollision);
|
|
349
368
|
return null;
|
|
350
369
|
}
|
|
@@ -356,6 +375,7 @@ class API {
|
|
|
356
375
|
if (!d.deviceCapabilities.includes(DeviceCapability_1.DeviceCapability.buttonSwitch)) {
|
|
357
376
|
return new Error(`Device with ID ${deviceId} is no switch`);
|
|
358
377
|
}
|
|
378
|
+
d.log(models_1.LogLevel.Info, `API Call to press button ${position} with ${pressType}`);
|
|
359
379
|
return d.pressButton(position, pressType);
|
|
360
380
|
}
|
|
361
381
|
}
|
|
@@ -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;
|