mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2026-07-12 22:59:00 +00:00
Improve expose of update sensors to HA (#9306)
* Improve expose of update sensors to HA * Update homeassistant.ts * Update homeassistant.ts * Update homeassistant.test.js * Update homeassistant.test.js Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
@@ -899,24 +899,25 @@ export default class HomeAssistant extends Extension {
|
||||
icon: 'mdi:update',
|
||||
value_template: `{{ value_json['update']['state'] }}`,
|
||||
enabled_by_default: false,
|
||||
entity_category: 'diagnostic',
|
||||
},
|
||||
};
|
||||
|
||||
configs.push(updateStateSensor);
|
||||
if (this.legacyApi) {
|
||||
const updateAvailableSensor = {
|
||||
type: 'binary_sensor',
|
||||
object_id: 'update_available',
|
||||
mockProperties: ['update_available'],
|
||||
discovery_payload: {
|
||||
payload_on: true,
|
||||
payload_off: false,
|
||||
value_template: '{{ value_json.update_available}}',
|
||||
enabled_by_default: false,
|
||||
},
|
||||
};
|
||||
configs.push(updateAvailableSensor);
|
||||
}
|
||||
const updateAvailableSensor = {
|
||||
type: 'binary_sensor',
|
||||
object_id: 'update_available',
|
||||
mockProperties: ['update_available'],
|
||||
discovery_payload: {
|
||||
payload_on: true,
|
||||
payload_off: false,
|
||||
value_template: `{{ value_json['update']['state'] == "available" }}`,
|
||||
enabled_by_default: true,
|
||||
device_class: 'update',
|
||||
entity_category: 'diagnostic',
|
||||
},
|
||||
};
|
||||
configs.push(updateAvailableSensor);
|
||||
}
|
||||
|
||||
if (isDevice && entity.settings.hasOwnProperty('legacy') && !entity.settings.legacy) {
|
||||
|
||||
@@ -1182,8 +1182,8 @@ describe('HomeAssistant extension', () => {
|
||||
const payload = {
|
||||
"payload_on":true,
|
||||
"payload_off":false,
|
||||
"value_template":"{{ value_json.update_available}}",
|
||||
"enabled_by_default": false,
|
||||
"value_template":`{{ value_json['update']['state'] == "available" }}`,
|
||||
"enabled_by_default": true,
|
||||
"state_topic":"zigbee2mqtt/bulb",
|
||||
"json_attributes_topic":"zigbee2mqtt/bulb",
|
||||
"name":"bulb update available",
|
||||
@@ -1198,6 +1198,8 @@ describe('HomeAssistant extension', () => {
|
||||
"manufacturer":"IKEA"
|
||||
},
|
||||
'availability': [{topic: 'zigbee2mqtt/bridge/state'}],
|
||||
'device_class': 'update',
|
||||
'entity_category': 'diagnostic'
|
||||
};
|
||||
|
||||
expect(MQTT.publish).toHaveBeenCalledWith(
|
||||
|
||||
Reference in New Issue
Block a user