hoffmation-base 3.0.0-alpha.43 → 3.0.0-alpha.45
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 +2 -2
- package/lib/server/config/iConfig.d.ts +3 -2
- package/lib/server/config/iGoveeSettings.d.ts +9 -0
- package/lib/server/config/iGoveeSettings.js +2 -0
- package/lib/server/config/index.d.ts +1 -0
- package/lib/server/services/ac/ac-device.js +1 -0
- package/lib/server/services/govee/govee-device-data.d.ts +25 -0
- package/lib/server/services/govee/govee-device-data.js +2 -0
- package/lib/server/services/govee/govee-service.d.ts +7 -5
- package/lib/server/services/govee/govee-service.js +72 -45
- package/lib/server/services/govee/own-govee-device.d.ts +3 -5
- package/lib/server/services/govee/own-govee-device.js +34 -33
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -2
package/lib/index.js
CHANGED
|
@@ -84,9 +84,9 @@ class HoffmationBase {
|
|
|
84
84
|
server_1.SonosService.addOwnDevices(server_1.OwnSonosDevices.ownDevices);
|
|
85
85
|
server_1.SonosService.initialize();
|
|
86
86
|
}
|
|
87
|
-
if (server_1.SettingsService.settings.
|
|
87
|
+
if (server_1.SettingsService.settings.goveeSettings) {
|
|
88
88
|
server_1.GooveeService.addOwnDevices(server_1.OwnGoveeDevices.ownDevices);
|
|
89
|
-
server_1.GooveeService.initialize();
|
|
89
|
+
server_1.GooveeService.initialize(server_1.SettingsService.settings.goveeSettings);
|
|
90
90
|
}
|
|
91
91
|
if ((_b = server_1.SettingsService.settings.daikin) === null || _b === void 0 ? void 0 : _b.active) {
|
|
92
92
|
server_1.DaikinService.addOwnDevices(server_1.OwnAcDevices.ownDevices);
|
|
@@ -23,6 +23,7 @@ import { iEnergyManagerSettings } from './iEnergyManagerSettings';
|
|
|
23
23
|
import { iUnifiSettings } from './iUnifiSettings';
|
|
24
24
|
import { iBlockAutomaticHandlerDefaults } from './iBlockAutomaticHandlerDefaults';
|
|
25
25
|
import { iRestSettings } from './iRestSettings';
|
|
26
|
+
import { iGoveeSettings } from './iGoveeSettings';
|
|
26
27
|
/**
|
|
27
28
|
* The main configuration for Hoffmation normally stored in the `main-config.json` file.
|
|
28
29
|
*/
|
|
@@ -56,9 +57,9 @@ export interface iConfig {
|
|
|
56
57
|
*/
|
|
57
58
|
espresense?: iEspresenseSettings;
|
|
58
59
|
/**
|
|
59
|
-
*
|
|
60
|
+
* @see iGoveeSettings
|
|
60
61
|
*/
|
|
61
|
-
|
|
62
|
+
goveeSettings?: iGoveeSettings;
|
|
62
63
|
/**
|
|
63
64
|
* @see iHeaterSettings
|
|
64
65
|
*/
|
|
@@ -54,6 +54,7 @@ class AcDevice {
|
|
|
54
54
|
this._room = room;
|
|
55
55
|
if (room !== undefined && !this._movementCallbackAdded) {
|
|
56
56
|
this._movementCallbackAdded = true;
|
|
57
|
+
// TODO: Maybe change to any Movement
|
|
57
58
|
(_a = room === null || room === void 0 ? void 0 : room.PraesenzGroup) === null || _a === void 0 ? void 0 : _a.addFirstEnterCallback(this.onRoomFirstEnter.bind(this));
|
|
58
59
|
(_b = room === null || room === void 0 ? void 0 : room.PraesenzGroup) === null || _b === void 0 ? void 0 : _b.addLastLeftCallback(this.onRoomLastLeave.bind(this));
|
|
59
60
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for any device data updates
|
|
3
|
+
*/
|
|
4
|
+
export interface GoveeDeviceData {
|
|
5
|
+
/**
|
|
6
|
+
* The device id form Govee
|
|
7
|
+
*/
|
|
8
|
+
id: string;
|
|
9
|
+
/**
|
|
10
|
+
* The current state
|
|
11
|
+
*/
|
|
12
|
+
actuatorOn: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The active brightness
|
|
15
|
+
*/
|
|
16
|
+
brightness: number;
|
|
17
|
+
/**
|
|
18
|
+
* The hex coded active color starting with #
|
|
19
|
+
*/
|
|
20
|
+
hexColor: string;
|
|
21
|
+
/**
|
|
22
|
+
* The colortemp
|
|
23
|
+
*/
|
|
24
|
+
colortemp: number;
|
|
25
|
+
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { OwnGoveeDevice } from './own-govee-device';
|
|
2
|
+
import { iGoveeSettings } from '../../config';
|
|
2
3
|
export declare class GooveeService {
|
|
3
|
-
private static
|
|
4
|
-
private static goveeApi;
|
|
4
|
+
private static _serverUrl;
|
|
5
5
|
private static ownDevices;
|
|
6
|
+
private static _refreshInterval;
|
|
6
7
|
static addOwnDevices(gvDevice: {
|
|
7
8
|
[name: string]: OwnGoveeDevice;
|
|
8
9
|
}): void;
|
|
9
|
-
static initialize(): void;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
static initialize(config: iGoveeSettings): void;
|
|
11
|
+
static cleanup(): void;
|
|
12
|
+
static sendCommand(device: OwnGoveeDevice, command: string): Promise<boolean>;
|
|
13
|
+
private static loadDevices;
|
|
12
14
|
}
|
|
@@ -1,63 +1,90 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.GooveeService = void 0;
|
|
4
27
|
const log_service_1 = require("../log-service");
|
|
5
28
|
const models_1 = require("../../../models");
|
|
6
|
-
const
|
|
29
|
+
const http = __importStar(require("http"));
|
|
30
|
+
const utils_1 = require("../utils");
|
|
7
31
|
class GooveeService {
|
|
8
32
|
static addOwnDevices(gvDevice) {
|
|
9
33
|
this.ownDevices = gvDevice;
|
|
10
34
|
}
|
|
11
|
-
static initialize() {
|
|
35
|
+
static initialize(config) {
|
|
12
36
|
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, 'Initializing Goovee-Service');
|
|
13
|
-
this.
|
|
14
|
-
|
|
15
|
-
discoverInterval: 300000,
|
|
16
|
-
});
|
|
17
|
-
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Scan, (data) => {
|
|
18
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `GoveeDevice ${data.ip} scanned`);
|
|
19
|
-
});
|
|
20
|
-
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Ready, () => {
|
|
21
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, 'Govee ready');
|
|
22
|
-
});
|
|
23
|
-
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.Error, (err) => {
|
|
24
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Govee-Error: ${err}`);
|
|
25
|
-
});
|
|
26
|
-
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.NewDevice, (device) => {
|
|
27
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `GoveeDevice ${device.id} joined`);
|
|
28
|
-
GooveeService.initializeDevice(device);
|
|
29
|
-
});
|
|
30
|
-
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.UnknownDevice, (_data) => {
|
|
31
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, 'GoveeDevice unknown');
|
|
32
|
-
});
|
|
33
|
-
this.goveeApi.on(govee_lan_controller_1.GoveeEventTypes.UnknownMessage, (data) => {
|
|
34
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `GoveeDevice unknown message: ${data}`);
|
|
35
|
-
});
|
|
36
|
-
this.goveeApi.discover();
|
|
37
|
+
this._serverUrl = config.url;
|
|
38
|
+
this._refreshInterval = utils_1.Utils.guardedInterval(this.loadDevices, 5000, this, true);
|
|
37
39
|
}
|
|
38
|
-
static
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return;
|
|
40
|
+
static cleanup() {
|
|
41
|
+
if (this._refreshInterval !== null) {
|
|
42
|
+
clearInterval(this._refreshInterval);
|
|
43
|
+
this._refreshInterval = null;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
}
|
|
46
|
+
static async sendCommand(device, command) {
|
|
47
|
+
return new Promise((resolve, _reject) => {
|
|
48
|
+
const requestLink = `${this._serverUrl}/device/${device.deviceId}/${command}`;
|
|
49
|
+
const req = http.get(requestLink, (res) => {
|
|
50
|
+
if (res.statusCode !== 200) {
|
|
51
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Failed to send Govee Command(${requestLink}): ${res.statusCode} - ${res.statusMessage}`);
|
|
52
|
+
resolve(false);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
resolve(true);
|
|
56
|
+
return;
|
|
57
|
+
});
|
|
58
|
+
req.on('error', (e) => {
|
|
59
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Govee Error: ${e.message}`);
|
|
60
|
+
});
|
|
50
61
|
});
|
|
51
|
-
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Govee ${d.id} found at address ${d.ipAddr}`);
|
|
52
62
|
}
|
|
53
|
-
static
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
63
|
+
static loadDevices() {
|
|
64
|
+
const req = http.get(`${this._serverUrl}/devices`, (res) => {
|
|
65
|
+
if (res.statusCode !== 200) {
|
|
66
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Alert, `Failed to load Govee Devices: ${res.statusCode}`);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
res.on('data', (d) => {
|
|
70
|
+
const data = JSON.parse(d.toString());
|
|
71
|
+
Object.keys(data).forEach((key) => {
|
|
72
|
+
const deviceData = data[key];
|
|
73
|
+
const ownDevice = this.ownDevices[key];
|
|
74
|
+
if (ownDevice === undefined) {
|
|
75
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.DeepTrace, `Unknown Govee Device "${key}"`);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
ownDevice.update(deviceData);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
req.on('error', (e) => {
|
|
83
|
+
log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Govee Error: ${e.message}`);
|
|
84
|
+
});
|
|
59
85
|
}
|
|
60
86
|
}
|
|
61
87
|
exports.GooveeService = GooveeService;
|
|
62
|
-
GooveeService.
|
|
88
|
+
GooveeService._serverUrl = 'http://127.0.0.1:3000';
|
|
63
89
|
GooveeService.ownDevices = {};
|
|
90
|
+
GooveeService._refreshInterval = null;
|
|
@@ -3,11 +3,9 @@ import { ActuatorSetStateCommand, ActuatorToggleCommand, ActuatorWriteStateToDev
|
|
|
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, DeviceStateInfo as GoveeDeviceStateInfo } from '@j3lte/govee-lan-controller';
|
|
7
6
|
import { BlockAutomaticHandler } from '../blockAutomaticHandler';
|
|
8
|
-
import {
|
|
7
|
+
import { GoveeDeviceData } from './govee-device-data';
|
|
9
8
|
export declare class OwnGoveeDevice implements iLedRgbCct, iTemporaryDisableAutomatic {
|
|
10
|
-
device: GoveeDevice | undefined;
|
|
11
9
|
/** @inheritDoc */
|
|
12
10
|
settings: LedSettings;
|
|
13
11
|
/** @inheritDoc */
|
|
@@ -31,7 +29,7 @@ export declare class OwnGoveeDevice implements iLedRgbCct, iTemporaryDisableAuto
|
|
|
31
29
|
private _color;
|
|
32
30
|
private _colortemp;
|
|
33
31
|
private _room;
|
|
34
|
-
constructor(deviceId: string, ownDeviceName: string, roomName: string
|
|
32
|
+
constructor(deviceId: string, ownDeviceName: string, roomName: string);
|
|
35
33
|
get color(): string;
|
|
36
34
|
get colortemp(): number;
|
|
37
35
|
get room(): RoomBase;
|
|
@@ -54,7 +52,7 @@ export declare class OwnGoveeDevice implements iLedRgbCct, iTemporaryDisableAuto
|
|
|
54
52
|
toggleActuator(c: ActuatorToggleCommand): boolean;
|
|
55
53
|
toggleLight(c: LampToggleLightCommand): boolean;
|
|
56
54
|
writeActuatorStateToDevice(c: ActuatorWriteStateToDeviceCommand): void;
|
|
57
|
-
update(data:
|
|
55
|
+
update(data: GoveeDeviceData): void;
|
|
58
56
|
private setBrightness;
|
|
59
57
|
private setColor;
|
|
60
58
|
private turnOn;
|
|
@@ -12,9 +12,9 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
12
12
|
const DeviceCapability_1 = require("../../devices/DeviceCapability");
|
|
13
13
|
const api_1 = require("../api");
|
|
14
14
|
const blockAutomaticHandler_1 = require("../blockAutomaticHandler");
|
|
15
|
+
const govee_service_1 = require("./govee-service");
|
|
15
16
|
class OwnGoveeDevice {
|
|
16
|
-
constructor(deviceId, ownDeviceName, roomName
|
|
17
|
-
this.device = device;
|
|
17
|
+
constructor(deviceId, ownDeviceName, roomName) {
|
|
18
18
|
/** @inheritDoc */
|
|
19
19
|
this.settings = new models_1.LedSettings();
|
|
20
20
|
/** @inheritDoc */
|
|
@@ -165,54 +165,55 @@ class OwnGoveeDevice {
|
|
|
165
165
|
}
|
|
166
166
|
update(data) {
|
|
167
167
|
this.queuedValue = null;
|
|
168
|
-
this._actuatorOn = data.
|
|
168
|
+
this._actuatorOn = data.actuatorOn;
|
|
169
169
|
this.brightness = data.brightness;
|
|
170
|
-
this._color =
|
|
171
|
-
this._colortemp = data.
|
|
170
|
+
this._color = data.hexColor;
|
|
171
|
+
this._colortemp = data.colortemp;
|
|
172
172
|
}
|
|
173
173
|
setBrightness(brightness, cb) {
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
govee_service_1.GooveeService.sendCommand(this, `brightness/${brightness}`).then((result) => {
|
|
175
|
+
if (!result) {
|
|
176
|
+
this.log(models_1.LogLevel.Error, 'Govee set brightness resulted in error');
|
|
177
|
+
}
|
|
176
178
|
cb();
|
|
177
|
-
}).catch((error) => {
|
|
178
|
-
this.log(models_1.LogLevel.Error, `Govee set brightness resulted in error: ${error}`);
|
|
179
179
|
});
|
|
180
180
|
}
|
|
181
181
|
setColor(color) {
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
(_a = this.device) === null || _a === void 0 ? void 0 : _a.setColorRGB(colors).then(() => {
|
|
192
|
-
this.log(models_1.LogLevel.Debug, `Govee set color to ${color}`, log_service_1.LogDebugType.SetActuator);
|
|
193
|
-
}).catch((error) => {
|
|
194
|
-
this.log(models_1.LogLevel.Error, `Govee set color resulted in error: ${error}`);
|
|
182
|
+
govee_service_1.GooveeService.sendCommand(this, `color/${color.replace('#', '')}`).then((result) => {
|
|
183
|
+
if (!result) {
|
|
184
|
+
this.log(models_1.LogLevel.Error, 'Govee set color resulted in error');
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
this.log(models_1.LogLevel.Debug, `Govee set color to ${color}`, log_service_1.LogDebugType.SetActuator);
|
|
188
|
+
}
|
|
195
189
|
});
|
|
196
190
|
}
|
|
197
191
|
turnOn() {
|
|
198
|
-
var _a;
|
|
199
192
|
if (this._actuatorOn) {
|
|
200
193
|
return;
|
|
201
194
|
}
|
|
202
195
|
this.queuedValue = true;
|
|
203
|
-
(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
196
|
+
govee_service_1.GooveeService.sendCommand(this, `on/true`).then((result) => {
|
|
197
|
+
if (!result) {
|
|
198
|
+
this.log(models_1.LogLevel.Error, 'Govee turn on resulted in error');
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
this.log(models_1.LogLevel.Debug, `Govee turned on`, log_service_1.LogDebugType.SetActuator);
|
|
202
|
+
}
|
|
207
203
|
});
|
|
208
204
|
}
|
|
209
205
|
turnOff() {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
206
|
+
if (this._actuatorOn) {
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.queuedValue = true;
|
|
210
|
+
govee_service_1.GooveeService.sendCommand(this, `on/false`).then((result) => {
|
|
211
|
+
if (!result) {
|
|
212
|
+
this.log(models_1.LogLevel.Error, 'Govee turn off resulted in error');
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
this.log(models_1.LogLevel.Debug, `Govee turned off`, log_service_1.LogDebugType.SetActuator);
|
|
216
|
+
}
|
|
216
217
|
});
|
|
217
218
|
}
|
|
218
219
|
}
|