Skip to content

Commit

Permalink
Plug devices: Properly set initial power state
Browse files Browse the repository at this point in the history
‘status’ can get a value of empty string (at least in the case of the
Zigbee gateway-based power plugs), which used to get translated to a
'false' power state. This would cause the triggering of the powerChanged
event twice on initialisation if the device was on already, with the
empty string case being the second call. This would cause users that monitor
the ‘powerChanged’ event to falsely report a power plug as off.

This fix explicitly allows for the empty string case, and avoids updating
the power state in this case.
  • Loading branch information
pieter committed Apr 30, 2018
1 parent b9b554e commit a74d6de
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/devices/capabilities/power.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { Thing, SwitchablePower } = require('abstract-things');

module.exports = Thing.mixin(Parent => class extends Parent.with(SwitchablePower) {
propertyUpdated(key, value) {
if(key === 'power') {
if(key === 'power' && value !== undefined) {
this.updatePower(value);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/devices/gateway/plug.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = class Plug extends SubDevice

this.defineProperty('status', {
name: 'power',
mapper: v => v === 'on'
mapper: v => (v === '') ? undefined : (v === 'on')
});

this.defineProperty('load_voltage', {
Expand Down

0 comments on commit a74d6de

Please sign in to comment.