@nubisco/homebridge-tuya-local-platform 1.0.0
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/LICENSE +9 -0
- package/README.md +48 -0
- package/config.schema.json +852 -0
- package/dist/accessories/AirConditioner.accessory.d.ts +50 -0
- package/dist/accessories/AirConditioner.accessory.d.ts.map +1 -0
- package/dist/accessories/AirConditioner.accessory.js +447 -0
- package/dist/accessories/AirConditioner.accessory.js.map +1 -0
- package/dist/accessories/AirPurifier.accessory.d.ts +37 -0
- package/dist/accessories/AirPurifier.accessory.d.ts.map +1 -0
- package/dist/accessories/AirPurifier.accessory.js +414 -0
- package/dist/accessories/AirPurifier.accessory.js.map +1 -0
- package/dist/accessories/Base.accessory.d.ts +43 -0
- package/dist/accessories/Base.accessory.d.ts.map +1 -0
- package/dist/accessories/Base.accessory.js +310 -0
- package/dist/accessories/Base.accessory.js.map +1 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.d.ts +47 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.d.ts.map +1 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.js +274 -0
- package/dist/accessories/CircuitBreakerMonitor.accessory.js.map +1 -0
- package/dist/accessories/Convector.accessory.d.ts +43 -0
- package/dist/accessories/Convector.accessory.d.ts.map +1 -0
- package/dist/accessories/Convector.accessory.js +297 -0
- package/dist/accessories/Convector.accessory.js.map +1 -0
- package/dist/accessories/CustomMultiOutlet.accessory.d.ts +15 -0
- package/dist/accessories/CustomMultiOutlet.accessory.d.ts.map +1 -0
- package/dist/accessories/CustomMultiOutlet.accessory.js +105 -0
- package/dist/accessories/CustomMultiOutlet.accessory.js.map +1 -0
- package/dist/accessories/Dehumidifier.accessory.d.ts +38 -0
- package/dist/accessories/Dehumidifier.accessory.d.ts.map +1 -0
- package/dist/accessories/Dehumidifier.accessory.js +264 -0
- package/dist/accessories/Dehumidifier.accessory.js.map +1 -0
- package/dist/accessories/EnergyCharacteristics.d.ts +4 -0
- package/dist/accessories/EnergyCharacteristics.d.ts.map +1 -0
- package/dist/accessories/EnergyCharacteristics.js +103 -0
- package/dist/accessories/EnergyCharacteristics.js.map +1 -0
- package/dist/accessories/GarageDoor.accessory.d.ts +30 -0
- package/dist/accessories/GarageDoor.accessory.d.ts.map +1 -0
- package/dist/accessories/GarageDoor.accessory.js +228 -0
- package/dist/accessories/GarageDoor.accessory.js.map +1 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.d.ts +49 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.d.ts.map +1 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.js +292 -0
- package/dist/accessories/MappedHeatPumpHeater.accessory.js.map +1 -0
- package/dist/accessories/MultiOutlet.accessory.d.ts +15 -0
- package/dist/accessories/MultiOutlet.accessory.d.ts.map +1 -0
- package/dist/accessories/MultiOutlet.accessory.js +101 -0
- package/dist/accessories/MultiOutlet.accessory.js.map +1 -0
- package/dist/accessories/OilDiffuser.accessory.d.ts +67 -0
- package/dist/accessories/OilDiffuser.accessory.d.ts.map +1 -0
- package/dist/accessories/OilDiffuser.accessory.js +466 -0
- package/dist/accessories/OilDiffuser.accessory.js.map +1 -0
- package/dist/accessories/Outlet.accessory.d.ts +11 -0
- package/dist/accessories/Outlet.accessory.d.ts.map +1 -0
- package/dist/accessories/Outlet.accessory.js +87 -0
- package/dist/accessories/Outlet.accessory.js.map +1 -0
- package/dist/accessories/RGBTWLight.accessory.d.ts +37 -0
- package/dist/accessories/RGBTWLight.accessory.d.ts.map +1 -0
- package/dist/accessories/RGBTWLight.accessory.js +237 -0
- package/dist/accessories/RGBTWLight.accessory.js.map +1 -0
- package/dist/accessories/RGBTWOutlet.accessory.d.ts +38 -0
- package/dist/accessories/RGBTWOutlet.accessory.d.ts.map +1 -0
- package/dist/accessories/RGBTWOutlet.accessory.js +305 -0
- package/dist/accessories/RGBTWOutlet.accessory.js.map +1 -0
- package/dist/accessories/SimpleBlinds.accessory.d.ts +32 -0
- package/dist/accessories/SimpleBlinds.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleBlinds.accessory.js +286 -0
- package/dist/accessories/SimpleBlinds.accessory.js.map +1 -0
- package/dist/accessories/SimpleDimmer.accessory.d.ts +14 -0
- package/dist/accessories/SimpleDimmer.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleDimmer.accessory.js +54 -0
- package/dist/accessories/SimpleDimmer.accessory.js.map +1 -0
- package/dist/accessories/SimpleDimmer2.accessory.d.ts +14 -0
- package/dist/accessories/SimpleDimmer2.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleDimmer2.accessory.js +53 -0
- package/dist/accessories/SimpleDimmer2.accessory.js.map +1 -0
- package/dist/accessories/SimpleFan.accessory.d.ts +21 -0
- package/dist/accessories/SimpleFan.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleFan.accessory.js +125 -0
- package/dist/accessories/SimpleFan.accessory.js.map +1 -0
- package/dist/accessories/SimpleFanLight.accessory.d.ts +31 -0
- package/dist/accessories/SimpleFanLight.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleFanLight.accessory.js +191 -0
- package/dist/accessories/SimpleFanLight.accessory.js.map +1 -0
- package/dist/accessories/SimpleHeater.accessory.d.ts +28 -0
- package/dist/accessories/SimpleHeater.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleHeater.accessory.js +175 -0
- package/dist/accessories/SimpleHeater.accessory.js.map +1 -0
- package/dist/accessories/SimpleLight.accessory.d.ts +11 -0
- package/dist/accessories/SimpleLight.accessory.d.ts.map +1 -0
- package/dist/accessories/SimpleLight.accessory.js +38 -0
- package/dist/accessories/SimpleLight.accessory.js.map +1 -0
- package/dist/accessories/Switch.accessory.d.ts +15 -0
- package/dist/accessories/Switch.accessory.d.ts.map +1 -0
- package/dist/accessories/Switch.accessory.js +101 -0
- package/dist/accessories/Switch.accessory.js.map +1 -0
- package/dist/accessories/TWLight.accessory.d.ts +19 -0
- package/dist/accessories/TWLight.accessory.d.ts.map +1 -0
- package/dist/accessories/TWLight.accessory.js +88 -0
- package/dist/accessories/TWLight.accessory.js.map +1 -0
- package/dist/accessories/Valve.accessory.d.ts +15 -0
- package/dist/accessories/Valve.accessory.d.ts.map +1 -0
- package/dist/accessories/Valve.accessory.js +144 -0
- package/dist/accessories/Valve.accessory.js.map +1 -0
- package/dist/accessories/index.d.ts +25 -0
- package/dist/accessories/index.d.ts.map +1 -0
- package/dist/accessories/index.js +55 -0
- package/dist/accessories/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +206 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol/TuyaAccessory.d.ts +45 -0
- package/dist/protocol/TuyaAccessory.d.ts.map +1 -0
- package/dist/protocol/TuyaAccessory.js +646 -0
- package/dist/protocol/TuyaAccessory.js.map +1 -0
- package/dist/protocol/TuyaDiscovery.d.ts +27 -0
- package/dist/protocol/TuyaDiscovery.d.ts.map +1 -0
- package/dist/protocol/TuyaDiscovery.js +141 -0
- package/dist/protocol/TuyaDiscovery.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +109 -0
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class BaseAccessory {
|
|
4
|
+
platform;
|
|
5
|
+
accessory;
|
|
6
|
+
device;
|
|
7
|
+
log;
|
|
8
|
+
hap;
|
|
9
|
+
colorFunction;
|
|
10
|
+
dpColor;
|
|
11
|
+
__ret;
|
|
12
|
+
constructor(...props) {
|
|
13
|
+
let isNew;
|
|
14
|
+
[this.platform, this.accessory, this.device, isNew = true] = [...props];
|
|
15
|
+
({
|
|
16
|
+
log: this.log,
|
|
17
|
+
api: { hap: this.hap },
|
|
18
|
+
} = this.platform);
|
|
19
|
+
if (isNew)
|
|
20
|
+
this._registerPlatformAccessory();
|
|
21
|
+
this.accessory.on('identify', ((paired, callback) => {
|
|
22
|
+
this.log('%s - identify', this.device.context.name);
|
|
23
|
+
callback();
|
|
24
|
+
}));
|
|
25
|
+
this.device.once('connect', () => {
|
|
26
|
+
this.log('Connected to', this.device.context.name);
|
|
27
|
+
});
|
|
28
|
+
this.device.once('change', () => {
|
|
29
|
+
this.log(`Ready to handle ${this.device.context.name} (${this.device.context.type}:${this.device.context.version}) with signature ${JSON.stringify(this.device.state)}`);
|
|
30
|
+
this._registerCharacteristics(this.device.state);
|
|
31
|
+
});
|
|
32
|
+
this.device._connect();
|
|
33
|
+
}
|
|
34
|
+
_registerPlatformAccessory() {
|
|
35
|
+
this.platform.registerPlatformAccessories(this.accessory);
|
|
36
|
+
}
|
|
37
|
+
_registerCharacteristics(_dps) {
|
|
38
|
+
// Override in subclasses
|
|
39
|
+
}
|
|
40
|
+
_checkServiceName(service, name) {
|
|
41
|
+
const { Characteristic } = this.hap;
|
|
42
|
+
if (service.displayName !== name) {
|
|
43
|
+
const nameCharacteristic = service.getCharacteristic(Characteristic.Name) || service.addCharacteristic(Characteristic.Name);
|
|
44
|
+
nameCharacteristic.setValue(name);
|
|
45
|
+
service.displayName = name;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_removeCharacteristic(service, characteristicType) {
|
|
49
|
+
if (!service || !characteristicType || !characteristicType.UUID)
|
|
50
|
+
return;
|
|
51
|
+
service.characteristics.some((characteristic) => {
|
|
52
|
+
if (!characteristic || characteristic.UUID !== characteristicType.UUID)
|
|
53
|
+
return false;
|
|
54
|
+
service.removeCharacteristic(characteristic);
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
_getCustomDP(numeral) {
|
|
59
|
+
return isFinite(numeral) && parseInt(numeral) > 0 ? String(numeral) : false;
|
|
60
|
+
}
|
|
61
|
+
_coerceBoolean(b, defaultValue) {
|
|
62
|
+
const df = defaultValue || false;
|
|
63
|
+
return typeof b === 'boolean'
|
|
64
|
+
? b
|
|
65
|
+
: typeof b === 'string'
|
|
66
|
+
? b.toLowerCase().trim() === 'true'
|
|
67
|
+
: typeof b === 'number'
|
|
68
|
+
? b !== 0
|
|
69
|
+
: df;
|
|
70
|
+
}
|
|
71
|
+
getState(dp, callback) {
|
|
72
|
+
if (!this.device.connected)
|
|
73
|
+
return callback(new Error('Not connected'));
|
|
74
|
+
const _callback = () => {
|
|
75
|
+
if (Array.isArray(dp)) {
|
|
76
|
+
const ret = {};
|
|
77
|
+
dp.forEach((p) => {
|
|
78
|
+
ret[p] = this.device.state[p];
|
|
79
|
+
});
|
|
80
|
+
callback(null, ret);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
callback(null, this.device.state[dp]);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
process.nextTick(_callback);
|
|
87
|
+
}
|
|
88
|
+
setState(dp, value, callback) {
|
|
89
|
+
this.setMultiState({ [dp.toString()]: value }, callback);
|
|
90
|
+
}
|
|
91
|
+
setMultiStateLegacy(dps, callback) {
|
|
92
|
+
if (!this.device.connected)
|
|
93
|
+
return callback(new Error('Not connected'));
|
|
94
|
+
const ret = this.device.update(dps);
|
|
95
|
+
if (callback)
|
|
96
|
+
callback(!ret ? new Error('Update failed') : null);
|
|
97
|
+
}
|
|
98
|
+
setMultiState(dps, callback) {
|
|
99
|
+
if (!this.device.connected) {
|
|
100
|
+
if (callback)
|
|
101
|
+
callback(new Error('Not connected'));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
for (const dp in dps) {
|
|
105
|
+
if (dps.hasOwnProperty(dp) && dps[dp] !== this.device.state[dp]) {
|
|
106
|
+
this.__ret = this.device.update({ [dp.toString()]: dps[dp] });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (callback)
|
|
110
|
+
callback(!this.__ret ? new Error('Update failed') : null);
|
|
111
|
+
}
|
|
112
|
+
getDividedState(dp, divisor, callback) {
|
|
113
|
+
this.getState(dp, (err, data) => {
|
|
114
|
+
if (err)
|
|
115
|
+
return callback(err);
|
|
116
|
+
if (!isFinite(data))
|
|
117
|
+
return callback(new Error('Invalid data'));
|
|
118
|
+
callback(null, this._getDividedState(data, divisor));
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
_getDividedState(dp, divisor) {
|
|
122
|
+
return parseFloat(dp) / divisor || 0;
|
|
123
|
+
}
|
|
124
|
+
_detectColorFunction(value) {
|
|
125
|
+
this.colorFunction =
|
|
126
|
+
this.device.context.colorFunction &&
|
|
127
|
+
{ HSB: 'HSB', HEXHSB: 'HEXHSB' }[this.device.context.colorFunction.toUpperCase()];
|
|
128
|
+
if (!this.colorFunction && value) {
|
|
129
|
+
this.colorFunction = { 12: 'HSB', 14: 'HEXHSB' }[value.length] || 'Unknown';
|
|
130
|
+
if (this.colorFunction)
|
|
131
|
+
this.log.info(`Color format for ${this.device.context.name} (${this.device.context.version}) identified as ${this.colorFunction} (length: ${value.length}).`);
|
|
132
|
+
}
|
|
133
|
+
if (!this.colorFunction) {
|
|
134
|
+
this.colorFunction = 'Unknown';
|
|
135
|
+
this.log.info(`Color format for ${this.device.context.name} (${this.device.context.version}) is undetectable.`);
|
|
136
|
+
}
|
|
137
|
+
else if (this.colorFunction === 'HSB') {
|
|
138
|
+
if (!this.device.context.scaleBrightness)
|
|
139
|
+
this.device.context.scaleBrightness = 1000;
|
|
140
|
+
if (!this.device.context.scaleWhiteColor)
|
|
141
|
+
this.device.context.scaleWhiteColor = 1000;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
convertBrightnessFromHomeKitToTuya(value) {
|
|
145
|
+
const min = this.device.context.minBrightness || 27;
|
|
146
|
+
const scale = this.device.context.scaleBrightness || 255;
|
|
147
|
+
return Math.round(((scale - min) * value + 100 * min - scale) / 99);
|
|
148
|
+
}
|
|
149
|
+
convertBrightnessFromTuyaToHomeKit(value) {
|
|
150
|
+
const min = this.device.context.minBrightness || 27;
|
|
151
|
+
const scale = this.device.context.scaleBrightness || 255;
|
|
152
|
+
return Math.round((99 * (Number(value) || 0) - 100 * min + scale) / (scale - min));
|
|
153
|
+
}
|
|
154
|
+
convertRotationSpeedFromHomeKitToTuya(value) {
|
|
155
|
+
const max = this.device.context.maxSpeed || 3;
|
|
156
|
+
const scale = Math.floor(100 / max);
|
|
157
|
+
return Math.round(value / scale);
|
|
158
|
+
}
|
|
159
|
+
convertRotationSpeedFromTuyaToHomeKit(value) {
|
|
160
|
+
const max = this.device.context.maxSpeed || 3;
|
|
161
|
+
const scale = Math.max(100 / max);
|
|
162
|
+
return Math.round(Number(value) * scale);
|
|
163
|
+
}
|
|
164
|
+
convertColorTemperatureFromHomeKitToTuya(value) {
|
|
165
|
+
const min = this.device.context.minWhiteColor || 140;
|
|
166
|
+
const max = this.device.context.maxWhiteColor || 400;
|
|
167
|
+
const scale = this.device.context.scaleWhiteColor || 255;
|
|
168
|
+
const adjustedValue = ((value - 71) * (max - min)) / (600 - 71) + 153;
|
|
169
|
+
const convertedValue = Math.round(((scale * min) / (max - min)) * (max / adjustedValue - 1));
|
|
170
|
+
return Math.min(scale, Math.max(0, convertedValue));
|
|
171
|
+
}
|
|
172
|
+
convertColorTemperatureFromTuyaToHomeKit(value) {
|
|
173
|
+
const min = this.device.context.minWhiteColor || 140;
|
|
174
|
+
const max = this.device.context.maxWhiteColor || 400;
|
|
175
|
+
const scale = this.device.context.scaleWhiteColor || 255;
|
|
176
|
+
const unadjustedValue = max / ((Number(value) * (max - min)) / (scale * min) + 1);
|
|
177
|
+
const convertedValue = Math.round(((unadjustedValue - 153) * (600 - 71)) / (max - min) + 71);
|
|
178
|
+
return Math.min(600, Math.max(71, convertedValue));
|
|
179
|
+
}
|
|
180
|
+
convertColorFromHomeKitToTuya(value, dpValue) {
|
|
181
|
+
switch (this.device.context.colorFunction) {
|
|
182
|
+
case 'HSB':
|
|
183
|
+
return this.convertColorFromHomeKitToTuya_HSB(value, dpValue);
|
|
184
|
+
default:
|
|
185
|
+
return this.convertColorFromHomeKitToTuya_HEXHSB(value, dpValue);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
convertColorFromHomeKitToTuya_HEXHSB(value, dpValue) {
|
|
189
|
+
const cached = this.convertColorFromTuya_HEXHSB_ToHomeKit(dpValue || this.device.state[this.dpColor]);
|
|
190
|
+
const { h, s, b } = { ...cached, ...value };
|
|
191
|
+
const hsb = h.toString(16).padStart(4, '0') +
|
|
192
|
+
Math.round(2.55 * s)
|
|
193
|
+
.toString(16)
|
|
194
|
+
.padStart(2, '0') +
|
|
195
|
+
Math.round(2.55 * b)
|
|
196
|
+
.toString(16)
|
|
197
|
+
.padStart(2, '0');
|
|
198
|
+
const hNorm = h / 60;
|
|
199
|
+
const sNorm = s / 100;
|
|
200
|
+
const bNorm = b * 2.55;
|
|
201
|
+
const i = Math.floor(hNorm);
|
|
202
|
+
const f = hNorm - i;
|
|
203
|
+
const p = bNorm * (1 - sNorm);
|
|
204
|
+
const q = bNorm * (1 - sNorm * f);
|
|
205
|
+
const t = bNorm * (1 - sNorm * (1 - f));
|
|
206
|
+
const rgb = (() => {
|
|
207
|
+
switch (i % 6) {
|
|
208
|
+
case 0:
|
|
209
|
+
return [bNorm, t, p];
|
|
210
|
+
case 1:
|
|
211
|
+
return [q, bNorm, p];
|
|
212
|
+
case 2:
|
|
213
|
+
return [p, bNorm, t];
|
|
214
|
+
case 3:
|
|
215
|
+
return [p, q, bNorm];
|
|
216
|
+
case 4:
|
|
217
|
+
return [t, p, bNorm];
|
|
218
|
+
case 5:
|
|
219
|
+
return [bNorm, p, q];
|
|
220
|
+
default:
|
|
221
|
+
return [bNorm, t, p];
|
|
222
|
+
}
|
|
223
|
+
})().map((c) => Math.round(c).toString(16).padStart(2, '0'));
|
|
224
|
+
const hex = rgb.join('');
|
|
225
|
+
return hex + hsb;
|
|
226
|
+
}
|
|
227
|
+
convertColorFromHomeKitToTuya_HSB(value, dpValue) {
|
|
228
|
+
const cached = this.convertColorFromTuya_HSB_ToHomeKit(dpValue || this.device.state[this.dpColor]);
|
|
229
|
+
const { h, s, b } = { ...cached, ...value };
|
|
230
|
+
return (h.toString(16).padStart(4, '0') + (10 * s).toString(16).padStart(4, '0') + (10 * b).toString(16).padStart(4, '0'));
|
|
231
|
+
}
|
|
232
|
+
convertColorFromTuyaToHomeKit(value) {
|
|
233
|
+
switch (this.device.context.colorFunction) {
|
|
234
|
+
case 'HSB':
|
|
235
|
+
return this.convertColorFromTuya_HSB_ToHomeKit(value);
|
|
236
|
+
default:
|
|
237
|
+
return this.convertColorFromTuya_HEXHSB_ToHomeKit(value);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
convertColorFromTuya_HEXHSB_ToHomeKit(value) {
|
|
241
|
+
const [, h, s, b] = (value || '0000000000ffff').match(/^.{6}([0-9a-f]{4})([0-9a-f]{2})([0-9a-f]{2})$/i) || [
|
|
242
|
+
'0',
|
|
243
|
+
'0',
|
|
244
|
+
'ff',
|
|
245
|
+
'ff',
|
|
246
|
+
];
|
|
247
|
+
return {
|
|
248
|
+
h: parseInt(h, 16),
|
|
249
|
+
s: Math.round(parseInt(s, 16) / 2.55),
|
|
250
|
+
b: Math.round(parseInt(b, 16) / 2.55),
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
convertColorFromTuya_HSB_ToHomeKit(value) {
|
|
254
|
+
const [, h, s, b] = (value || '000003e803e8').match(/^([0-9a-f]{4})([0-9a-f]{4})([0-9a-f]{4})$/i) || [
|
|
255
|
+
'0',
|
|
256
|
+
'0',
|
|
257
|
+
'3e8',
|
|
258
|
+
'3e8',
|
|
259
|
+
];
|
|
260
|
+
return {
|
|
261
|
+
h: parseInt(h, 16),
|
|
262
|
+
s: Math.round(parseInt(s, 16) / 10),
|
|
263
|
+
b: Math.round(parseInt(b, 16) / 10),
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
convertHomeKitColorTemperatureToHomeKitColor(value) {
|
|
267
|
+
const dKelvin = 10000 / value;
|
|
268
|
+
const rgb = [
|
|
269
|
+
dKelvin > 66
|
|
270
|
+
? 351.97690566805693 + 0.114206453784165 * (dKelvin - 55) - 40.25366309332127 * Math.log(dKelvin - 55)
|
|
271
|
+
: 255,
|
|
272
|
+
dKelvin > 66
|
|
273
|
+
? 325.4494125711974 + 0.07943456536662342 * (dKelvin - 50) - 28.0852963507957 * Math.log(dKelvin - 55)
|
|
274
|
+
: 104.49216199393888 * Math.log(dKelvin - 2) - 0.44596950469579133 * (dKelvin - 2) - 155.25485562709179,
|
|
275
|
+
dKelvin > 66
|
|
276
|
+
? 255
|
|
277
|
+
: 115.67994401066147 * Math.log(dKelvin - 10) + 0.8274096064007395 * (dKelvin - 10) - 254.76935184120902,
|
|
278
|
+
].map((v) => Math.max(0, Math.min(255, v)) / 255);
|
|
279
|
+
const max = Math.max(...rgb);
|
|
280
|
+
const min = Math.min(...rgb);
|
|
281
|
+
const d = max - min;
|
|
282
|
+
let h = 0;
|
|
283
|
+
const s = max ? (100 * d) / max : 0;
|
|
284
|
+
const b = 100 * max;
|
|
285
|
+
if (d) {
|
|
286
|
+
switch (max) {
|
|
287
|
+
case rgb[0]:
|
|
288
|
+
h = (rgb[1] - rgb[2]) / d + (rgb[1] < rgb[2] ? 6 : 0);
|
|
289
|
+
break;
|
|
290
|
+
case rgb[1]:
|
|
291
|
+
h = (rgb[2] - rgb[0]) / d + 2;
|
|
292
|
+
break;
|
|
293
|
+
default:
|
|
294
|
+
h = (rgb[0] - rgb[1]) / d + 4;
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
h *= 60;
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
h: Math.round(h),
|
|
301
|
+
s: Math.round(s),
|
|
302
|
+
b: Math.round(b),
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
adaptiveLightingSupport() {
|
|
306
|
+
return !!(this.platform.api.versionGreaterOrEqual && this.platform.api.versionGreaterOrEqual('v1.3.0-beta.23'));
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.default = BaseAccessory;
|
|
310
|
+
//# sourceMappingURL=Base.accessory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Base.accessory.js","sourceRoot":"","sources":["../../src/accessories/Base.accessory.ts"],"names":[],"mappings":";;AASA,MAAM,aAAa;IACjB,QAAQ,CAAM;IACd,SAAS,CAAoB;IAC7B,MAAM,CAAgB;IACtB,GAAG,CAAM;IACT,GAAG,CAAa;IAChB,aAAa,CAAU;IACvB,OAAO,CAAU;IACT,KAAK,CAAW;IAExB,YAAY,GAAG,KAAY;QACzB,IAAI,KAAc,CAAC;QACnB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;QACxE,CAAC;YACC,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,GAAG,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;SACvB,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAEnB,IAAI,KAAK;YAAE,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAE7C,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,MAAe,EAAE,QAAoB,EAAE,EAAE;YACvE,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YACpD,QAAQ,EAAE,CAAC;QACb,CAAC,CAAQ,CAAC,CAAC;QAEX,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE;YAC/B,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,C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AAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBAC9B,MAAM;gBACR;oBACE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;oBAC9B,MAAM;YACV,CAAC;YACD,CAAC,IAAI,EAAE,CAAC;QACV,CAAC;QACD,OAAO;YACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAChB,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;YAChB,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;SACjB,CAAC;IACJ,CAAC;IAED,uBAAuB;QACrB,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,qBAAqB,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAClH,CAAC;CACF;AAED,kBAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import BaseAccessory from './Base.accessory';
|
|
2
|
+
import type { DPSState, DPSValue, HomebridgeCallback, CircuitBreakerTelemetry, PhaseData } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Circuit Breaker Monitor Accessory
|
|
5
|
+
*
|
|
6
|
+
* SAFETY-CRITICAL DEVICE - READ-ONLY MONITORING ONLY
|
|
7
|
+
*
|
|
8
|
+
* This accessory exposes telemetry from a Tuya-based digital circuit breaker/energy meter.
|
|
9
|
+
* The breaker switch (DP 16) is NEVER exposed to HomeKit.
|
|
10
|
+
*
|
|
11
|
+
* HomeKit Services Exposed:
|
|
12
|
+
* 1. TemperatureSensor - Device temperature monitoring
|
|
13
|
+
* 2. LeakSensor - Leakage current warning (configurable threshold)
|
|
14
|
+
* 3. ContactSensor - Fault alarm indicator
|
|
15
|
+
*/
|
|
16
|
+
declare class CircuitBreakerMonitorAccessory extends BaseAccessory {
|
|
17
|
+
static getCategory(Categories: any): number;
|
|
18
|
+
temperatureSensor: any;
|
|
19
|
+
leakSensor: any;
|
|
20
|
+
faultSensor: any;
|
|
21
|
+
dpTemperature: string;
|
|
22
|
+
dpLeakageCurrent: string;
|
|
23
|
+
dpFault: string;
|
|
24
|
+
dpTotalForwardEnergy: string;
|
|
25
|
+
dpPhaseA: string;
|
|
26
|
+
dpSwitch: string;
|
|
27
|
+
temperatureDivisor: number;
|
|
28
|
+
energyDivisor: number;
|
|
29
|
+
leakageThreshold: number;
|
|
30
|
+
telemetry: CircuitBreakerTelemetry;
|
|
31
|
+
constructor(...props: any[]);
|
|
32
|
+
_registerPlatformAccessory(): void;
|
|
33
|
+
_registerCharacteristics(dps: DPSState): void;
|
|
34
|
+
getTemperature(callback: HomebridgeCallback): void;
|
|
35
|
+
_getTemperature(dps: DPSState): number;
|
|
36
|
+
getLeakDetected(callback: HomebridgeCallback): void;
|
|
37
|
+
_getLeakDetected(dps: DPSState): number;
|
|
38
|
+
getFaultState(callback: HomebridgeCallback): void;
|
|
39
|
+
_getFaultState(dps: DPSState): number;
|
|
40
|
+
_processDeviceChanges(changes: DPSState, state: DPSState): void;
|
|
41
|
+
_updateTelemetry(dps: DPSState): void;
|
|
42
|
+
_logTelemetry(): void;
|
|
43
|
+
_decodePhaseData(rawPayload: DPSValue): void;
|
|
44
|
+
_parsePhasePayload(_buffer: Buffer): PhaseData;
|
|
45
|
+
}
|
|
46
|
+
export default CircuitBreakerMonitorAccessory;
|
|
47
|
+
//# sourceMappingURL=CircuitBreakerMonitor.accessory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CircuitBreakerMonitor.accessory.d.ts","sourceRoot":"","sources":["../../src/accessories/CircuitBreakerMonitor.accessory.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,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BAAgB,CAAC,UAAU,EAAE,QAAQ,GAAG,IAAI;IAuC5C,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS;CAS/C;AAED,eAAe,8BAA8B,CAAC"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Base_accessory_1 = __importDefault(require("./Base.accessory"));
|
|
7
|
+
/**
|
|
8
|
+
* Circuit Breaker Monitor Accessory
|
|
9
|
+
*
|
|
10
|
+
* SAFETY-CRITICAL DEVICE - READ-ONLY MONITORING ONLY
|
|
11
|
+
*
|
|
12
|
+
* This accessory exposes telemetry from a Tuya-based digital circuit breaker/energy meter.
|
|
13
|
+
* The breaker switch (DP 16) is NEVER exposed to HomeKit.
|
|
14
|
+
*
|
|
15
|
+
* HomeKit Services Exposed:
|
|
16
|
+
* 1. TemperatureSensor - Device temperature monitoring
|
|
17
|
+
* 2. LeakSensor - Leakage current warning (configurable threshold)
|
|
18
|
+
* 3. ContactSensor - Fault alarm indicator
|
|
19
|
+
*/
|
|
20
|
+
class CircuitBreakerMonitorAccessory extends Base_accessory_1.default {
|
|
21
|
+
static getCategory(Categories) {
|
|
22
|
+
return Categories.SENSOR;
|
|
23
|
+
}
|
|
24
|
+
temperatureSensor;
|
|
25
|
+
leakSensor;
|
|
26
|
+
faultSensor;
|
|
27
|
+
dpTemperature;
|
|
28
|
+
dpLeakageCurrent;
|
|
29
|
+
dpFault;
|
|
30
|
+
dpTotalForwardEnergy;
|
|
31
|
+
dpPhaseA;
|
|
32
|
+
dpSwitch;
|
|
33
|
+
temperatureDivisor;
|
|
34
|
+
energyDivisor;
|
|
35
|
+
leakageThreshold;
|
|
36
|
+
telemetry;
|
|
37
|
+
constructor(...props) {
|
|
38
|
+
super(...props);
|
|
39
|
+
}
|
|
40
|
+
_registerPlatformAccessory() {
|
|
41
|
+
const { Service } = this.hap;
|
|
42
|
+
this.accessory.category = this.constructor.getCategory(this.hap.Categories);
|
|
43
|
+
// Primary service: Device Temperature Sensor
|
|
44
|
+
this.temperatureSensor = this.accessory.getService(Service.TemperatureSensor);
|
|
45
|
+
if (!this.temperatureSensor && this.device.context.exposeTemperatureSensor !== false) {
|
|
46
|
+
this.temperatureSensor = this.accessory.addService(Service.TemperatureSensor, this.device.context.name);
|
|
47
|
+
}
|
|
48
|
+
// Leakage Current Warning
|
|
49
|
+
this.leakSensor = this.accessory.getService(Service.LeakSensor);
|
|
50
|
+
if (!this.leakSensor && this.device.context.exposeLeakSensor !== false) {
|
|
51
|
+
this.leakSensor = this.accessory.addService(Service.LeakSensor, this.device.context.leakSensorName || this.device.context.name + ' Leakage');
|
|
52
|
+
}
|
|
53
|
+
// Fault Alarm Sensor
|
|
54
|
+
this.faultSensor = this.accessory.getService(Service.ContactSensor);
|
|
55
|
+
if (!this.faultSensor && this.device.context.exposeFaultSensor !== false) {
|
|
56
|
+
this.faultSensor = this.accessory.addService(Service.ContactSensor, this.device.context.faultSensorName || this.device.context.name + ' Fault');
|
|
57
|
+
}
|
|
58
|
+
super._registerPlatformAccessory();
|
|
59
|
+
}
|
|
60
|
+
_registerCharacteristics(dps) {
|
|
61
|
+
const { Characteristic } = this.hap;
|
|
62
|
+
// DP configuration with defaults
|
|
63
|
+
this.dpTemperature = this._getCustomDP(this.device.context.dpTemperature) || '103';
|
|
64
|
+
this.dpLeakageCurrent = this._getCustomDP(this.device.context.dpLeakageCurrent) || '15';
|
|
65
|
+
this.dpFault = this._getCustomDP(this.device.context.dpFault) || '9';
|
|
66
|
+
this.dpTotalForwardEnergy = this._getCustomDP(this.device.context.dpTotalForwardEnergy) || '1';
|
|
67
|
+
this.dpPhaseA = this._getCustomDP(this.device.context.dpPhaseA) || '6';
|
|
68
|
+
this.dpSwitch = this._getCustomDP(this.device.context.dpSwitch) || '16';
|
|
69
|
+
// Divisors
|
|
70
|
+
this.temperatureDivisor = this.device.context.temperatureDivisor || 1;
|
|
71
|
+
this.energyDivisor = this.device.context.energyDivisor || 100;
|
|
72
|
+
// Leakage threshold (mA)
|
|
73
|
+
this.leakageThreshold = this.device.context.leakageThreshold || 30;
|
|
74
|
+
// Internal telemetry storage
|
|
75
|
+
this.telemetry = {
|
|
76
|
+
totalForwardEnergy: undefined,
|
|
77
|
+
leakageCurrent: undefined,
|
|
78
|
+
temperature: undefined,
|
|
79
|
+
fault: undefined,
|
|
80
|
+
switchState: undefined,
|
|
81
|
+
phaseData: undefined,
|
|
82
|
+
};
|
|
83
|
+
// Register Temperature Sensor
|
|
84
|
+
if (this.temperatureSensor) {
|
|
85
|
+
this._checkServiceName(this.temperatureSensor, this.device.context.name);
|
|
86
|
+
this.temperatureSensor
|
|
87
|
+
.getCharacteristic(Characteristic.CurrentTemperature)
|
|
88
|
+
.setProps({
|
|
89
|
+
minValue: -100,
|
|
90
|
+
maxValue: 150,
|
|
91
|
+
})
|
|
92
|
+
.updateValue(this._getTemperature(dps))
|
|
93
|
+
.on('get', this.getTemperature.bind(this));
|
|
94
|
+
}
|
|
95
|
+
// Register Leak Sensor
|
|
96
|
+
if (this.leakSensor) {
|
|
97
|
+
this._checkServiceName(this.leakSensor, this.device.context.leakSensorName || this.device.context.name + ' Leakage');
|
|
98
|
+
this.leakSensor
|
|
99
|
+
.getCharacteristic(Characteristic.LeakDetected)
|
|
100
|
+
.updateValue(this._getLeakDetected(dps))
|
|
101
|
+
.on('get', this.getLeakDetected.bind(this));
|
|
102
|
+
}
|
|
103
|
+
// Register Fault Sensor
|
|
104
|
+
if (this.faultSensor) {
|
|
105
|
+
this._checkServiceName(this.faultSensor, this.device.context.faultSensorName || this.device.context.name + ' Fault');
|
|
106
|
+
this.faultSensor
|
|
107
|
+
.getCharacteristic(Characteristic.ContactSensorState)
|
|
108
|
+
.updateValue(this._getFaultState(dps))
|
|
109
|
+
.on('get', this.getFaultState.bind(this));
|
|
110
|
+
}
|
|
111
|
+
// Listen for device updates
|
|
112
|
+
this.device.on('change', (changes, state) => {
|
|
113
|
+
this._processDeviceChanges(changes, state);
|
|
114
|
+
});
|
|
115
|
+
// Initial telemetry update
|
|
116
|
+
this._updateTelemetry(dps);
|
|
117
|
+
this._logTelemetry();
|
|
118
|
+
}
|
|
119
|
+
// Temperature Sensor
|
|
120
|
+
getTemperature(callback) {
|
|
121
|
+
this.getState(this.dpTemperature, (err, dp) => {
|
|
122
|
+
if (err)
|
|
123
|
+
return callback(err);
|
|
124
|
+
callback(null, this._getTemperature({ [this.dpTemperature]: dp }));
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
_getTemperature(dps) {
|
|
128
|
+
const rawValue = dps[this.dpTemperature];
|
|
129
|
+
if (rawValue === undefined || rawValue === null) {
|
|
130
|
+
this.log.warn('[CircuitBreakerMonitor] Temperature DP %s is undefined', this.dpTemperature);
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
const temperature = parseFloat(String(rawValue)) / this.temperatureDivisor;
|
|
134
|
+
this.telemetry.temperature = temperature;
|
|
135
|
+
return temperature;
|
|
136
|
+
}
|
|
137
|
+
// Leak Detection (Leakage Current)
|
|
138
|
+
getLeakDetected(callback) {
|
|
139
|
+
this.getState(this.dpLeakageCurrent, (err, dp) => {
|
|
140
|
+
if (err)
|
|
141
|
+
return callback(err);
|
|
142
|
+
callback(null, this._getLeakDetected({ [this.dpLeakageCurrent]: dp }));
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
_getLeakDetected(dps) {
|
|
146
|
+
const { Characteristic } = this.hap;
|
|
147
|
+
const rawValue = dps[this.dpLeakageCurrent];
|
|
148
|
+
if (rawValue === undefined || rawValue === null) {
|
|
149
|
+
this.log.warn('[CircuitBreakerMonitor] Leakage current DP %s is undefined', this.dpLeakageCurrent);
|
|
150
|
+
return Characteristic.LeakDetected.LEAK_NOT_DETECTED;
|
|
151
|
+
}
|
|
152
|
+
const leakageCurrent = parseFloat(String(rawValue));
|
|
153
|
+
this.telemetry.leakageCurrent = leakageCurrent;
|
|
154
|
+
const isLeaking = leakageCurrent >= this.leakageThreshold;
|
|
155
|
+
if (isLeaking) {
|
|
156
|
+
this.log.warn('[CircuitBreakerMonitor] ⚠️ LEAKAGE DETECTED: %d mA (threshold: %d mA)', leakageCurrent, this.leakageThreshold);
|
|
157
|
+
}
|
|
158
|
+
return isLeaking ? Characteristic.LeakDetected.LEAK_DETECTED : Characteristic.LeakDetected.LEAK_NOT_DETECTED;
|
|
159
|
+
}
|
|
160
|
+
// Fault Detection
|
|
161
|
+
getFaultState(callback) {
|
|
162
|
+
this.getState(this.dpFault, (err, dp) => {
|
|
163
|
+
if (err)
|
|
164
|
+
return callback(err);
|
|
165
|
+
callback(null, this._getFaultState({ [this.dpFault]: dp }));
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
_getFaultState(dps) {
|
|
169
|
+
const { Characteristic } = this.hap;
|
|
170
|
+
const rawValue = dps[this.dpFault];
|
|
171
|
+
if (rawValue === undefined || rawValue === null) {
|
|
172
|
+
this.log.warn('[CircuitBreakerMonitor] Fault DP %s is undefined', this.dpFault);
|
|
173
|
+
return Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
174
|
+
}
|
|
175
|
+
const faultBitmap = parseInt(String(rawValue));
|
|
176
|
+
this.telemetry.fault = faultBitmap;
|
|
177
|
+
const hasFault = faultBitmap !== 0;
|
|
178
|
+
if (hasFault) {
|
|
179
|
+
this.log.warn('[CircuitBreakerMonitor] ⚠️ FAULT DETECTED: bitmap = 0x%s', faultBitmap.toString(16));
|
|
180
|
+
}
|
|
181
|
+
return hasFault
|
|
182
|
+
? Characteristic.ContactSensorState.CONTACT_DETECTED
|
|
183
|
+
: Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
184
|
+
}
|
|
185
|
+
// Telemetry Updates (Internal Only)
|
|
186
|
+
_processDeviceChanges(changes, state) {
|
|
187
|
+
const { Characteristic } = this.hap;
|
|
188
|
+
this._updateTelemetry(state);
|
|
189
|
+
if (changes.hasOwnProperty(this.dpTemperature) && this.temperatureSensor) {
|
|
190
|
+
this.temperatureSensor
|
|
191
|
+
.getCharacteristic(Characteristic.CurrentTemperature)
|
|
192
|
+
.updateValue(this._getTemperature(state));
|
|
193
|
+
}
|
|
194
|
+
if (changes.hasOwnProperty(this.dpLeakageCurrent) && this.leakSensor) {
|
|
195
|
+
this.leakSensor.getCharacteristic(Characteristic.LeakDetected).updateValue(this._getLeakDetected(state));
|
|
196
|
+
}
|
|
197
|
+
if (changes.hasOwnProperty(this.dpFault) && this.faultSensor) {
|
|
198
|
+
this.faultSensor.getCharacteristic(Characteristic.ContactSensorState).updateValue(this._getFaultState(state));
|
|
199
|
+
}
|
|
200
|
+
// Log switch state changes but NEVER expose to HomeKit
|
|
201
|
+
if (changes.hasOwnProperty(this.dpSwitch)) {
|
|
202
|
+
const switchState = state[this.dpSwitch];
|
|
203
|
+
this.log('[CircuitBreakerMonitor] Breaker switch state: %s (READ-ONLY, NOT EXPOSED)', switchState ? 'ON' : 'OFF');
|
|
204
|
+
}
|
|
205
|
+
if (changes.hasOwnProperty(this.dpPhaseA)) {
|
|
206
|
+
this._decodePhaseData(state[this.dpPhaseA]);
|
|
207
|
+
}
|
|
208
|
+
if (Object.keys(changes).length > 0) {
|
|
209
|
+
this._logTelemetry();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
_updateTelemetry(dps) {
|
|
213
|
+
if (dps[this.dpTotalForwardEnergy] !== undefined) {
|
|
214
|
+
const rawEnergy = parseInt(String(dps[this.dpTotalForwardEnergy]));
|
|
215
|
+
this.telemetry.totalForwardEnergy = rawEnergy / this.energyDivisor;
|
|
216
|
+
}
|
|
217
|
+
if (dps[this.dpTemperature] !== undefined) {
|
|
218
|
+
this.telemetry.temperature = parseFloat(String(dps[this.dpTemperature])) / this.temperatureDivisor;
|
|
219
|
+
}
|
|
220
|
+
if (dps[this.dpLeakageCurrent] !== undefined) {
|
|
221
|
+
this.telemetry.leakageCurrent = parseFloat(String(dps[this.dpLeakageCurrent]));
|
|
222
|
+
}
|
|
223
|
+
if (dps[this.dpFault] !== undefined) {
|
|
224
|
+
this.telemetry.fault = parseInt(String(dps[this.dpFault]));
|
|
225
|
+
}
|
|
226
|
+
if (dps[this.dpSwitch] !== undefined) {
|
|
227
|
+
this.telemetry.switchState = Boolean(dps[this.dpSwitch]);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
_logTelemetry() {
|
|
231
|
+
const t = this.telemetry;
|
|
232
|
+
this.log('[CircuitBreakerMonitor] Telemetry: ' + 'Energy=%s kWh, Temp=%s°C, Leakage=%s mA, Fault=0x%s, Switch=%s', t.totalForwardEnergy !== undefined ? t.totalForwardEnergy.toFixed(2) : 'N/A', t.temperature !== undefined ? t.temperature.toFixed(1) : 'N/A', t.leakageCurrent !== undefined ? t.leakageCurrent.toFixed(0) : 'N/A', t.fault !== undefined ? t.fault.toString(16) : 'N/A', t.switchState !== undefined ? (t.switchState ? 'ON' : 'OFF') : 'N/A');
|
|
233
|
+
}
|
|
234
|
+
// Phase Data Decoder (DP 6)
|
|
235
|
+
_decodePhaseData(rawPayload) {
|
|
236
|
+
try {
|
|
237
|
+
if (!rawPayload) {
|
|
238
|
+
this.log.warn('[CircuitBreakerMonitor] Phase data (DP %s) is undefined', this.dpPhaseA);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
let buffer;
|
|
242
|
+
if (typeof rawPayload === 'string') {
|
|
243
|
+
buffer = Buffer.from(rawPayload, 'base64');
|
|
244
|
+
}
|
|
245
|
+
else if (Buffer.isBuffer(rawPayload)) {
|
|
246
|
+
buffer = rawPayload;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
this.log.warn('[CircuitBreakerMonitor] Unexpected phase data type: %s', typeof rawPayload);
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
this.log.debug('[CircuitBreakerMonitor] Phase data (DP %s) raw buffer: %s', this.dpPhaseA, buffer.toString('hex'));
|
|
253
|
+
const phaseData = this._parsePhasePayload(buffer);
|
|
254
|
+
this.telemetry.phaseData = phaseData;
|
|
255
|
+
if (phaseData.voltage !== undefined || phaseData.current !== undefined || phaseData.power !== undefined) {
|
|
256
|
+
this.log('[CircuitBreakerMonitor] Phase: V=%s V, I=%s A, P=%s W', phaseData.voltage !== undefined ? phaseData.voltage.toFixed(1) : 'N/A', phaseData.current !== undefined ? phaseData.current.toFixed(2) : 'N/A', phaseData.power !== undefined ? phaseData.power.toFixed(0) : 'N/A');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
catch (err) {
|
|
260
|
+
this.log.warn('[CircuitBreakerMonitor] Failed to decode phase data: %s', err.message);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
_parsePhasePayload(_buffer) {
|
|
264
|
+
// Stub implementation - return structure
|
|
265
|
+
// TODO: Implement actual parsing when format is determined
|
|
266
|
+
return {
|
|
267
|
+
voltage: undefined,
|
|
268
|
+
current: undefined,
|
|
269
|
+
power: undefined,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.default = CircuitBreakerMonitorAccessory;
|
|
274
|
+
//# sourceMappingURL=CircuitBreakerMonitor.accessory.js.map
|