diff --git a/.gitignore b/.gitignore index 3f441697..b7397888 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.DS_Store /node_modules /.node-persist +/.vscode diff --git a/accessories/outlet.js b/accessories/outlet.js index 4b2ab0b1..8a57f266 100644 --- a/accessories/outlet.js +++ b/accessories/outlet.js @@ -9,13 +9,14 @@ class OutletAccessory extends SwitchAccessory { const { config, state, serviceManager } = this; const newState = active ? true : false; + const previousState = state.outletInUse; + // Only update Homkit if the switch state haven changed. - if (previousState === newState) return + if (previousState != undefined && previousState === newState) return + state.outletInUse = newState; if (config.pingIPAddressStateOnly) { - state.outletInUse = newState; serviceManager.refreshCharacteristicUI(Characteristic.OutletInUse) - return } diff --git a/test/helpers/fakeHomebridge.js b/test/helpers/fakeHomebridge.js new file mode 100644 index 00000000..05077c32 --- /dev/null +++ b/test/helpers/fakeHomebridge.js @@ -0,0 +1,20 @@ +class FakeUser{ + constructor(){ + this.storage = "../sotragePath"; + } + + storagePath (){ + return this.storage; + } +} + +class FakeHomebridge{ + + constructor () { + this.user = new FakeUser(); + } + + +} + +module.exports = FakeHomebridge; diff --git a/test/helpers/setup.js b/test/helpers/setup.js index 6cd80065..e6a75fd0 100644 --- a/test/helpers/setup.js +++ b/test/helpers/setup.js @@ -1,5 +1,5 @@ const hap = require('hap-nodejs'); - +const FakeHomebridge = require('./fakeHomebridge') const BroadlinkRMPlatform = require('../../platform'); const FakeDevice = require('./fakeDevice') const { addDevice } = require('../../helpers/getDevice') @@ -16,6 +16,8 @@ const log = (message, more) => { }; const setup = (config) => { + const homebridge = new FakeHomebridge(); + BroadlinkRMPlatform.setHomebridge(homebridge); const platform = new BroadlinkRMPlatform(log, config); const device = new FakeDevice() diff --git a/test/light.test.js b/test/light.test.js index 0d14f00b..554fb1d8 100644 --- a/test/light.test.js +++ b/test/light.test.js @@ -621,7 +621,7 @@ describe('lightAccessory', () => { // Check that only one code has been sent sentHexCodeCount = device.getSentHexCodeCount(); - expect(sentHexCodeCount).to.equal(2); + expect(sentHexCodeCount).to.equal(1); });