homebridge-tuya-plus 4.3.0-dev.110 → 4.3.0-dev.112
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/index.js +3 -1
- package/lib/OutletAccessory.js +2 -1
- package/lib/RGBTWOutletAccessory.js +2 -1
- package/package.json +1 -1
- package/test/OutletAccessory.test.js +19 -0
- package/test/index.test.js +11 -0
package/index.js
CHANGED
|
@@ -158,7 +158,9 @@ class TuyaLan {
|
|
|
158
158
|
// unless cloud credentials are configured.
|
|
159
159
|
this.cloudApi = null;
|
|
160
160
|
this.cloudMessaging = null;
|
|
161
|
-
|
|
161
|
+
// Kept on the platform, not api.hap: HAP-NodeJS 2.3.0 (Homebridge 2.5)
|
|
162
|
+
// made the hap export non-extensible, so assigning to it throws on startup.
|
|
163
|
+
this.EnergyCharacteristics = require('./lib/EnergyCharacteristics')(
|
|
162
164
|
this.api.hap,
|
|
163
165
|
);
|
|
164
166
|
|
package/lib/OutletAccessory.js
CHANGED
|
@@ -18,7 +18,8 @@ class OutletAccessory extends BaseAccessory {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
_registerCharacteristics(dps) {
|
|
21
|
-
const {Service, Characteristic
|
|
21
|
+
const {Service, Characteristic} = this.hap;
|
|
22
|
+
const {EnergyCharacteristics} = this.platform;
|
|
22
23
|
const service = this.accessory.getService(Service.Outlet);
|
|
23
24
|
this._checkServiceName(service, this.device.context.name);
|
|
24
25
|
|
|
@@ -41,7 +41,8 @@ class RGBTWOutletAccessory extends BaseAccessory {
|
|
|
41
41
|
_registerCharacteristics(dps) {
|
|
42
42
|
this._verifyCachedPlatformAccessory();
|
|
43
43
|
|
|
44
|
-
const {Service, Characteristic
|
|
44
|
+
const {Service, Characteristic} = this.hap;
|
|
45
|
+
const {EnergyCharacteristics} = this.platform;
|
|
45
46
|
|
|
46
47
|
const outletService = this.accessory.getServiceById(Service.Outlet, 'outlet');
|
|
47
48
|
const lightService = this.accessory.getServiceById(Service.Lightbulb, 'lightbulb');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-tuya-plus",
|
|
3
|
-
"version": "4.3.0-dev.
|
|
3
|
+
"version": "4.3.0-dev.112",
|
|
4
4
|
"description": "A community-maintained Homebridge plugin for controlling Tuya devices locally over LAN, with an optional Tuya Cloud fallback for whatever the LAN can't reach. Includes new features, fixes, and updated device support. PRs welcome: if it runs, it ships (almost).",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const OutletAccessory = require('../lib/OutletAccessory');
|
|
4
|
+
const { makeInstance } = require('./support/mocks');
|
|
5
|
+
|
|
6
|
+
describe('OutletAccessory — energy characteristics', () => {
|
|
7
|
+
test('are read from the platform, since api.hap is read-only on Homebridge 2.5', () => {
|
|
8
|
+
const { instance, platform, accessory } = makeInstance(OutletAccessory, {'1': true, '2': 2300}, {voltsId: '2'});
|
|
9
|
+
const Volts = jest.fn();
|
|
10
|
+
platform.EnergyCharacteristics = {Volts, Amperes: jest.fn(), Watts: jest.fn()};
|
|
11
|
+
instance._removeCharacteristic = jest.fn();
|
|
12
|
+
|
|
13
|
+
instance._registerCharacteristics({'1': true, '2': 2300});
|
|
14
|
+
|
|
15
|
+
expect(accessory._mockService.getCharacteristic).toHaveBeenCalledWith(Volts);
|
|
16
|
+
expect(instance._removeCharacteristic).toHaveBeenCalledWith(accessory._mockService, platform.EnergyCharacteristics.Amperes);
|
|
17
|
+
expect(instance._removeCharacteristic).toHaveBeenCalledWith(accessory._mockService, platform.EnergyCharacteristics.Watts);
|
|
18
|
+
});
|
|
19
|
+
});
|
package/test/index.test.js
CHANGED
|
@@ -85,6 +85,17 @@ const CLOUD = {accessId: 'aid', accessKey: 'akey', region: 'eu'};
|
|
|
85
85
|
beforeEach(() => { jest.clearAllMocks(); jest.useFakeTimers(); });
|
|
86
86
|
afterEach(() => { jest.useRealTimers(); });
|
|
87
87
|
|
|
88
|
+
describe('TuyaLan — read-only api.hap (Homebridge 2.5)', () => {
|
|
89
|
+
test('constructs without mutating api.hap and keeps the energy characteristics on the platform', () => {
|
|
90
|
+
const Platform = getPlatformClass();
|
|
91
|
+
const api = makeApi();
|
|
92
|
+
Object.freeze(api.hap);
|
|
93
|
+
const platform = new Platform(makeLog(), {devices: [SW()]}, api);
|
|
94
|
+
expect(api.hap.EnergyCharacteristics).toBeUndefined();
|
|
95
|
+
expect(platform.EnergyCharacteristics).toEqual(expect.objectContaining({Volts: expect.any(Function)}));
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
88
99
|
describe('TuyaLan — cloud session setup', () => {
|
|
89
100
|
test('no cloud config → no session, devices are pure-LAN', () => {
|
|
90
101
|
run({devices: [SW()]});
|