mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-16 02:18:31 -07:00
feat: Add support for button entity in Home Assistant (#21372)
* add button entity support * add enabled_by_default to select --------- Co-authored-by: Koen Kanters <koenkanters94@gmail.com>
This commit is contained in:
parent
0ab7390a64
commit
24b5f9b43a
@ -946,6 +946,7 @@ export default class HomeAssistant extends Extension {
|
|||||||
effect: {enabled_by_default: false, icon: 'mdi:palette'},
|
effect: {enabled_by_default: false, icon: 'mdi:palette'},
|
||||||
force: {entity_category: 'config', icon: 'mdi:valve'},
|
force: {entity_category: 'config', icon: 'mdi:valve'},
|
||||||
keep_time: {entity_category: 'config', icon: 'mdi:av-timer'},
|
keep_time: {entity_category: 'config', icon: 'mdi:av-timer'},
|
||||||
|
identify: {device_class: 'identify'},
|
||||||
keypad_lockout: {entity_category: 'config', icon: 'mdi:lock'},
|
keypad_lockout: {entity_category: 'config', icon: 'mdi:lock'},
|
||||||
load_detection_mode: {entity_category: 'config', icon: 'mdi:tune'},
|
load_detection_mode: {entity_category: 'config', icon: 'mdi:tune'},
|
||||||
load_dimmable: {entity_category: 'config', icon: 'mdi:chart-bell-curve'},
|
load_dimmable: {entity_category: 'config', icon: 'mdi:chart-bell-curve'},
|
||||||
@ -960,6 +961,7 @@ export default class HomeAssistant extends Extension {
|
|||||||
power_outage_memory: {entity_category: 'config', icon: 'mdi:power-settings'},
|
power_outage_memory: {entity_category: 'config', icon: 'mdi:power-settings'},
|
||||||
power_supply_mode: {entity_category: 'config', icon: 'mdi:power-settings'},
|
power_supply_mode: {entity_category: 'config', icon: 'mdi:power-settings'},
|
||||||
power_type: {entity_category: 'config', icon: 'mdi:lightning-bolt-circle'},
|
power_type: {entity_category: 'config', icon: 'mdi:lightning-bolt-circle'},
|
||||||
|
restart: {device_class: 'restart'},
|
||||||
sensitivity: {entity_category: 'config', icon: 'mdi:tune'},
|
sensitivity: {entity_category: 'config', icon: 'mdi:tune'},
|
||||||
sensor: {icon: 'mdi:tune'},
|
sensor: {icon: 'mdi:tune'},
|
||||||
sensors_type: {entity_category: 'config', icon: 'mdi:tune'},
|
sensors_type: {entity_category: 'config', icon: 'mdi:tune'},
|
||||||
@ -969,6 +971,7 @@ export default class HomeAssistant extends Extension {
|
|||||||
temperature_display_mode: {entity_category: 'config', icon: 'mdi:thermometer'},
|
temperature_display_mode: {entity_category: 'config', icon: 'mdi:thermometer'},
|
||||||
temperature_sensor_select: {entity_category: 'config', icon: 'mdi:home-thermometer'},
|
temperature_sensor_select: {entity_category: 'config', icon: 'mdi:home-thermometer'},
|
||||||
thermostat_unit: {entity_category: 'config', icon: 'mdi:thermometer'},
|
thermostat_unit: {entity_category: 'config', icon: 'mdi:thermometer'},
|
||||||
|
update: {device_class: 'update'},
|
||||||
volume: {entity_category: 'config', icon: 'mdi: volume-high'},
|
volume: {entity_category: 'config', icon: 'mdi: volume-high'},
|
||||||
week: {entity_category: 'config', icon: 'mdi:calendar-clock'},
|
week: {entity_category: 'config', icon: 'mdi:calendar-clock'},
|
||||||
};
|
};
|
||||||
@ -1008,6 +1011,29 @@ export default class HomeAssistant extends Extension {
|
|||||||
command_topic: true,
|
command_topic: true,
|
||||||
command_topic_postfix: firstExpose.property,
|
command_topic_postfix: firstExpose.property,
|
||||||
options: firstExpose.values.map((v) => v.toString()),
|
options: firstExpose.values.map((v) => v.toString()),
|
||||||
|
enabled_by_default: firstExpose.values.length !== 1, // hide if button is exposed
|
||||||
|
...lookup[firstExpose.name],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If enum has only item and only supports SET then expose as button entity.
|
||||||
|
* Note: select entity is hidden by default to avoid breaking changes
|
||||||
|
* for selects already existing in HA (legacy).
|
||||||
|
*/
|
||||||
|
if (firstExpose.access & ACCESS_SET && firstExpose.values.length === 1) {
|
||||||
|
discoveryEntries.push({
|
||||||
|
type: 'button',
|
||||||
|
object_id: firstExpose.property,
|
||||||
|
mockProperties: [],
|
||||||
|
discovery_payload: {
|
||||||
|
name: endpoint ? `${firstExpose.label} ${endpoint}` : firstExpose.label,
|
||||||
|
state_topic: false,
|
||||||
|
command_topic_prefix: endpoint,
|
||||||
|
command_topic: true,
|
||||||
|
command_topic_postfix: firstExpose.property,
|
||||||
|
payload_press: firstExpose.values[0].toString(),
|
||||||
...lookup[firstExpose.name],
|
...lookup[firstExpose.name],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -2530,7 +2530,8 @@ describe('HomeAssistant extension', () => {
|
|||||||
'origin': origin,
|
'origin': origin,
|
||||||
'state_topic':'zigbee2mqtt/0x18fc26000000cafe',
|
'state_topic':'zigbee2mqtt/0x18fc26000000cafe',
|
||||||
'unique_id':'0x18fc26000000cafe_device_mode_zigbee2mqtt',
|
'unique_id':'0x18fc26000000cafe_device_mode_zigbee2mqtt',
|
||||||
'value_template':'{{ value_json.device_mode }}'
|
'value_template':'{{ value_json.device_mode }}',
|
||||||
|
'enabled_by_default': true,
|
||||||
}
|
}
|
||||||
expect(MQTT.publish).toHaveBeenCalledWith(
|
expect(MQTT.publish).toHaveBeenCalledWith(
|
||||||
"homeassistant/select/0x18fc26000000cafe/device_mode/config",
|
"homeassistant/select/0x18fc26000000cafe/device_mode/config",
|
||||||
|
Loading…
Reference in New Issue
Block a user