Undiscover ota_update sensor on device remove.

This commit is contained in:
Koen Kanters
2020-02-22 00:32:15 +01:00
parent 6b5b4ab433
commit df67c429bf
+10 -7
View File
@@ -1266,7 +1266,7 @@ class HomeAssistant extends BaseExtension {
const mappedModel = zigbeeHerdsmanConverters.findByZigbeeModel(device.modelID);
if (mappedModel) {
logger.info(`Clearing Home Assistant discovery topic for '${device.ieeeAddr}'`);
mapping[mappedModel.model].forEach((config) => {
this.getConfigs(mappedModel).forEach((config) => {
const topic = this.getDiscoveryTopic(config, device);
this.mqtt.publish(topic, null, {retain: true, qos: 0}, this.discoveryTopic);
});
@@ -1285,6 +1285,14 @@ class HomeAssistant extends BaseExtension {
}
}
getConfigs(mappedModel) {
const configs = mapping[mappedModel.model].slice();
if (mappedModel.hasOwnProperty('ota')) {
configs.push(cfg.binary_sensor_update_available);
}
return configs;
}
discover(device, mappedModel, force=false) {
// Check if already discoverd and check if there are configs.
const discover = force || !this.discovered[device.ieeeAddr];
@@ -1298,12 +1306,7 @@ class HomeAssistant extends BaseExtension {
return;
}
const configs = mapping[mappedModel.model].slice();
if (mappedModel.hasOwnProperty('ota')) {
configs.push(cfg.binary_sensor_update_available);
}
configs.forEach((config) => {
this.getConfigs(mappedModel).forEach((config) => {
const topic = this.getDiscoveryTopic(config, device);
const payload = {...config.discovery_payload};
const stateTopic = `${settings.get().mqtt.base_topic}/${entity.friendlyName}`;