Skip to content

Commit

Permalink
Koenkk#2296 only publish /availability if the state has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sjorge committed Nov 9, 2019
1 parent b617239 commit abaa90f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/extension/deviceAvailability.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ class DeviceAvailability extends BaseExtension {
this.onReconnect(device);
}

this.state[ieeeAddr] = available;
const deviceSettings = settings.getDevice(ieeeAddr);
const name = deviceSettings ? deviceSettings.friendly_name : ieeeAddr;
const topic = `${name}/availability`;
const payload = available ? 'online' : 'offline';
this.mqtt.publish(topic, payload, {retain: true, qos: 0});
if (this.state[ieeeAddr] !== available) {
this.state[ieeeAddr] = available;
this.mqtt.publish(topic, payload, {retain: true, qos: 0});
}
}

onZigbeeEvent(type, data, mappedDevice, settingsDevice) {
Expand Down

0 comments on commit abaa90f

Please sign in to comment.