homebridge-tydom 0.23.8 → 0.23.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/README.md +1 -1
- package/lib/accessories/outlet.js +7 -8
- package/lib/bin/cli.js +6 -4
- package/lib/controller.d.ts +3 -2
- package/lib/controller.js +32 -24
- package/lib/helpers/tydom.js +0 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateOutlet = exports.setupOutlet = void 0;
|
|
4
|
-
const definitions_1 = require("hap-nodejs/dist/lib/definitions");
|
|
5
4
|
const lodash_1 = require("lodash");
|
|
6
5
|
const tydom_1 = require("../helpers/tydom");
|
|
7
6
|
const utils_1 = require("../utils");
|
|
@@ -10,7 +9,7 @@ const accessory_1 = require("../helpers/accessory");
|
|
|
10
9
|
const setupOutlet = (accessory, controller) => {
|
|
11
10
|
const { context } = accessory;
|
|
12
11
|
const { client } = controller;
|
|
13
|
-
const { On } = hap_1.Characteristic;
|
|
12
|
+
const { On, OutletInUse } = hap_1.Characteristic;
|
|
14
13
|
const { deviceId, endpointId } = context;
|
|
15
14
|
(0, accessory_1.setupAccessoryInformationService)(accessory, controller);
|
|
16
15
|
(0, accessory_1.setupAccessoryIdentifyHandler)(accessory, controller);
|
|
@@ -49,14 +48,14 @@ const setupOutlet = (accessory, controller) => {
|
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
service
|
|
52
|
-
.getCharacteristic(
|
|
51
|
+
.getCharacteristic(OutletInUse)
|
|
53
52
|
.on("get" /* CharacteristicEventTypes.GET */, async (callback) => {
|
|
54
|
-
(0, utils_1.debugGet)(
|
|
53
|
+
(0, utils_1.debugGet)(OutletInUse, service);
|
|
55
54
|
try {
|
|
56
55
|
const data = await (0, tydom_1.getTydomDeviceData)(client, { deviceId, endpointId });
|
|
57
56
|
const energyInstantTotElecP = (0, tydom_1.getTydomDataPropValue)(data, 'energyInstantTotElecP');
|
|
58
57
|
const nextValue = energyInstantTotElecP > 0;
|
|
59
|
-
(0, utils_1.debugGetResult)(
|
|
58
|
+
(0, utils_1.debugGetResult)(OutletInUse, service, nextValue);
|
|
60
59
|
callback(null, nextValue);
|
|
61
60
|
}
|
|
62
61
|
catch (err) {
|
|
@@ -68,7 +67,7 @@ exports.setupOutlet = setupOutlet;
|
|
|
68
67
|
const updateOutlet = (accessory, _controller, updates) => {
|
|
69
68
|
updates.forEach((update) => {
|
|
70
69
|
const { name, value } = update;
|
|
71
|
-
const { On } = hap_1.Characteristic;
|
|
70
|
+
const { On, OutletInUse } = hap_1.Characteristic;
|
|
72
71
|
switch (name) {
|
|
73
72
|
case 'level': {
|
|
74
73
|
const service = (0, accessory_1.getAccessoryService)(accessory, hap_1.Service.Outlet);
|
|
@@ -80,8 +79,8 @@ const updateOutlet = (accessory, _controller, updates) => {
|
|
|
80
79
|
case 'energyInstantTotElecP': {
|
|
81
80
|
const service = (0, accessory_1.getAccessoryService)(accessory, hap_1.Service.Outlet);
|
|
82
81
|
const nextValue = (0, lodash_1.toNumber)(value) > 0;
|
|
83
|
-
(0, utils_1.debugSetUpdate)(
|
|
84
|
-
service.updateCharacteristic(
|
|
82
|
+
(0, utils_1.debugSetUpdate)(OutletInUse, service, nextValue);
|
|
83
|
+
service.updateCharacteristic(OutletInUse, nextValue);
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
87
86
|
default:
|
package/lib/bin/cli.js
CHANGED
|
@@ -14,10 +14,12 @@ const main = async () => {
|
|
|
14
14
|
const allDevicesConfig = dump['/configs/file'];
|
|
15
15
|
const allDevicesMeta = dump['/devices/meta'];
|
|
16
16
|
for (const deviceMeta of allDevicesMeta) {
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
for (const endpointMeta of deviceMeta.endpoints) {
|
|
18
|
+
const signature = (0, tydom_1.getEndpointSignatureFromMetadata)(endpointMeta.metadata);
|
|
19
|
+
const config = allDevicesConfig.endpoints.find((item) => item.id_device === deviceMeta.id && item.id_endpoint === endpointMeta.id);
|
|
20
|
+
const hash = `${config === null || config === void 0 ? void 0 : config.first_usage}:${await (0, utils_1.sha256)(signature)}`;
|
|
21
|
+
console.dir({ id: `${deviceMeta.id}.${endpointMeta.id}`, name: config === null || config === void 0 ? void 0 : config.name, signature, hash });
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
break;
|
|
23
25
|
}
|
package/lib/controller.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { EventEmitter } from 'events';
|
|
3
|
-
import
|
|
3
|
+
import { Categories, Logging } from 'homebridge';
|
|
4
4
|
import TydomClient from 'tydom-client';
|
|
5
5
|
import { TydomHttpMessage, TydomResponse } from 'tydom-client/lib/utils/tydom';
|
|
6
6
|
import { TydomPlatformConfig } from './platform';
|
|
@@ -25,7 +25,8 @@ export default class TydomController extends EventEmitter {
|
|
|
25
25
|
private state;
|
|
26
26
|
private refreshInterval?;
|
|
27
27
|
constructor(log: Logging, config: TydomPlatformConfig);
|
|
28
|
-
|
|
28
|
+
getUniqueId(deviceId: number, endpointId: number): string;
|
|
29
|
+
getAccessoryId(deviceId: number, endpointId: number): string;
|
|
29
30
|
connect(): Promise<void>;
|
|
30
31
|
sync(): Promise<{
|
|
31
32
|
config: TydomConfigResponse;
|
package/lib/controller.js
CHANGED
|
@@ -43,9 +43,12 @@ class TydomController extends events_1.EventEmitter {
|
|
|
43
43
|
this.emit('disconnect');
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
|
|
46
|
+
getUniqueId(deviceId, endpointId) {
|
|
47
|
+
return deviceId === endpointId ? `${deviceId}` : `${deviceId}:${endpointId}`;
|
|
48
|
+
}
|
|
49
|
+
getAccessoryId(deviceId, endpointId) {
|
|
47
50
|
const { username } = this.config;
|
|
48
|
-
return `tydom:${username.slice(6)}:accessories:${deviceId}`;
|
|
51
|
+
return `tydom:${username.slice(6)}:accessories:${this.getUniqueId(deviceId, endpointId)}`;
|
|
49
52
|
}
|
|
50
53
|
async connect() {
|
|
51
54
|
const { hostname, username } = this.config;
|
|
@@ -95,6 +98,7 @@ class TydomController extends events_1.EventEmitter {
|
|
|
95
98
|
const { endpoints, groups: configGroups } = config;
|
|
96
99
|
endpoints.forEach((endpoint) => {
|
|
97
100
|
const { id_endpoint: endpointId, id_device: deviceId, name: deviceName, first_usage: firstUsage } = endpoint;
|
|
101
|
+
const uniqueId = this.getUniqueId(deviceId, endpointId);
|
|
98
102
|
const { metadata } = (0, tydom_1.getEndpointDetailsFromMeta)(endpoint, meta);
|
|
99
103
|
const groupId = (0, tydom_1.getEndpointGroupIdFromGroups)(endpoint, groups);
|
|
100
104
|
const group = groupId ? configGroups.find(({ id }) => id === groupId) : undefined;
|
|
@@ -120,12 +124,12 @@ class TydomController extends events_1.EventEmitter {
|
|
|
120
124
|
if (excludedCategories.length && (0, utils_1.stringIncludes)(excludedCategories, category)) {
|
|
121
125
|
return;
|
|
122
126
|
}
|
|
123
|
-
if (!this.devices.has(
|
|
127
|
+
if (!this.devices.has(uniqueId)) {
|
|
124
128
|
this.log.info(`Adding new device with firstUsage=${(0, utils_1.chalkString)(firstUsage)}, deviceId=${(0, utils_1.chalkNumber)(deviceId)} and endpointId=${(0, utils_1.chalkNumber)(endpointId)}`);
|
|
125
|
-
const accessoryId = this.getAccessoryId(deviceId);
|
|
129
|
+
const accessoryId = this.getAccessoryId(deviceId, endpointId);
|
|
126
130
|
const nameFromSetting = (0, lodash_1.get)(settings, `${deviceId}.name`);
|
|
127
131
|
const name = nameFromSetting || deviceName;
|
|
128
|
-
this.devices.set(
|
|
132
|
+
this.devices.set(uniqueId, category);
|
|
129
133
|
const context = {
|
|
130
134
|
name,
|
|
131
135
|
category,
|
|
@@ -168,27 +172,31 @@ class TydomController extends events_1.EventEmitter {
|
|
|
168
172
|
return;
|
|
169
173
|
}
|
|
170
174
|
body.forEach((device) => {
|
|
175
|
+
var _a;
|
|
171
176
|
const { id: deviceId, endpoints } = device;
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
for (const endpoint of endpoints) {
|
|
178
|
+
const { id: endpointId, data, cdata } = endpoint;
|
|
179
|
+
const updates = type === 'data' ? data : cdata;
|
|
180
|
+
const uniqueId = this.getUniqueId(deviceId, endpointId);
|
|
181
|
+
if (!this.devices.has(uniqueId)) {
|
|
182
|
+
(0, utils_1.debug)(`${chalk_1.default.bold.yellow('←PUT')}:${chalk_1.default.blue('ignored')} for device id=${(0, utils_1.chalkString)(deviceId)} and endpointId=${(0, utils_1.chalkNumber)(endpointId)}`);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const category = (_a = this.devices.get(uniqueId)) !== null && _a !== void 0 ? _a : 1 /* Categories.OTHER */;
|
|
186
|
+
const accessoryId = this.getAccessoryId(deviceId, endpointId);
|
|
187
|
+
(0, utils_1.debug)(`${chalk_1.default.bold.green('←PUT')}:${chalk_1.default.blue('update')} for deviceId=${(0, utils_1.chalkNumber)(deviceId)} and endpointId=${(0, utils_1.chalkNumber)(endpointId)}, updates:\n${(0, utils_1.chalkJson)(updates)}`);
|
|
188
|
+
const context = {
|
|
189
|
+
category,
|
|
190
|
+
deviceId,
|
|
191
|
+
endpointId,
|
|
192
|
+
accessoryId
|
|
193
|
+
};
|
|
194
|
+
this.emit('update', {
|
|
195
|
+
type,
|
|
196
|
+
updates,
|
|
197
|
+
context
|
|
198
|
+
});
|
|
175
199
|
}
|
|
176
|
-
const category = this.devices.get(deviceId);
|
|
177
|
-
const { id: endpointId, data, cdata } = endpoints[0];
|
|
178
|
-
const updates = type === 'data' ? data : cdata;
|
|
179
|
-
const accessoryId = this.getAccessoryId(deviceId);
|
|
180
|
-
(0, utils_1.debug)(`${chalk_1.default.bold.green('←PUT')}:${chalk_1.default.blue('update')} for device id=${(0, utils_1.chalkString)(deviceId)}, updates:\n${(0, utils_1.chalkJson)(updates)}`);
|
|
181
|
-
const context = {
|
|
182
|
-
category,
|
|
183
|
-
deviceId,
|
|
184
|
-
endpointId,
|
|
185
|
-
accessoryId
|
|
186
|
-
};
|
|
187
|
-
this.emit('update', {
|
|
188
|
-
type,
|
|
189
|
-
updates,
|
|
190
|
-
context
|
|
191
|
-
});
|
|
192
200
|
});
|
|
193
201
|
}
|
|
194
202
|
}
|
package/lib/helpers/tydom.js
CHANGED
|
@@ -96,7 +96,6 @@ const ENDPOINTS_SIGNATURES_CATEGORIES = {
|
|
|
96
96
|
'hvac:16804a9994bce28275150db329a9c0b931ef7f20608c1a3d2ff248f58569f0d3': 10 /* Categories.SENSOR */,
|
|
97
97
|
'hvac:17f933bec8ed29f9b2a2cd5280fb5b64806cf8a1c064c83950e350f491d7cb9f': 9 /* Categories.THERMOSTAT */,
|
|
98
98
|
'hvac:1bab47d1dd7e898b5dc2e9867b14dfb8bc9272c4cb0b5d1221da962d43a6ffb4': 9 /* Categories.THERMOSTAT */,
|
|
99
|
-
'hvac:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855': 10 /* Categories.SENSOR */,
|
|
100
99
|
'light:449e2a60377094cde10224cee91d378fb0ae373ae6ceea0ac2cbc1ed011bffa7': 5 /* Categories.LIGHTBULB */,
|
|
101
100
|
'light:fce45085835f4f2790ea3b17d208b5ace34935444d2535e75ba3f0a2ce86de5f': 5 /* Categories.LIGHTBULB */,
|
|
102
101
|
'others:449e2a60377094cde10224cee91d378fb0ae373ae6ceea0ac2cbc1ed011bffa7': 5 /* Categories.LIGHTBULB */,
|