mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add button platform to Homee (#138923)
This commit is contained in:
parent
6aae319b1a
commit
20f273f06a
@ -14,7 +14,7 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
PLATFORMS = [Platform.COVER, Platform.SENSOR, Platform.SWITCH]
|
PLATFORMS = [Platform.BUTTON, Platform.COVER, Platform.SENSOR, Platform.SWITCH]
|
||||||
|
|
||||||
type HomeeConfigEntry = ConfigEntry[Homee]
|
type HomeeConfigEntry = ConfigEntry[Homee]
|
||||||
|
|
||||||
|
78
homeassistant/components/homee/button.py
Normal file
78
homeassistant/components/homee/button.py
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
"""The homee button platform."""
|
||||||
|
|
||||||
|
from pyHomee.const import AttributeType
|
||||||
|
from pyHomee.model import HomeeAttribute
|
||||||
|
|
||||||
|
from homeassistant.components.button import (
|
||||||
|
ButtonDeviceClass,
|
||||||
|
ButtonEntity,
|
||||||
|
ButtonEntityDescription,
|
||||||
|
)
|
||||||
|
from homeassistant.const import EntityCategory
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||||
|
|
||||||
|
from . import HomeeConfigEntry
|
||||||
|
from .entity import HomeeEntity
|
||||||
|
|
||||||
|
BUTTON_DESCRIPTIONS: dict[AttributeType, ButtonEntityDescription] = {
|
||||||
|
AttributeType.AUTOMATIC_MODE_IMPULSE: ButtonEntityDescription(key="automatic_mode"),
|
||||||
|
AttributeType.BRIEFLY_OPEN_IMPULSE: ButtonEntityDescription(key="briefly_open"),
|
||||||
|
AttributeType.IDENTIFICATION_MODE: ButtonEntityDescription(
|
||||||
|
key="identification_mode",
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
device_class=ButtonDeviceClass.IDENTIFY,
|
||||||
|
),
|
||||||
|
AttributeType.IMPULSE: ButtonEntityDescription(key="impulse"),
|
||||||
|
AttributeType.LIGHT_IMPULSE: ButtonEntityDescription(key="light"),
|
||||||
|
AttributeType.OPEN_PARTIAL_IMPULSE: ButtonEntityDescription(key="open_partial"),
|
||||||
|
AttributeType.PERMANENTLY_OPEN_IMPULSE: ButtonEntityDescription(
|
||||||
|
key="permanently_open"
|
||||||
|
),
|
||||||
|
AttributeType.RESET_METER: ButtonEntityDescription(
|
||||||
|
key="reset_meter",
|
||||||
|
entity_category=EntityCategory.CONFIG,
|
||||||
|
),
|
||||||
|
AttributeType.VENTILATE_IMPULSE: ButtonEntityDescription(key="ventilate"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def async_setup_entry(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
config_entry: HomeeConfigEntry,
|
||||||
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||||
|
) -> None:
|
||||||
|
"""Add the Homee platform for the button component."""
|
||||||
|
|
||||||
|
async_add_entities(
|
||||||
|
HomeeButton(attribute, config_entry, BUTTON_DESCRIPTIONS[attribute.type])
|
||||||
|
for node in config_entry.runtime_data.nodes
|
||||||
|
for attribute in node.attributes
|
||||||
|
if attribute.type in BUTTON_DESCRIPTIONS and attribute.editable
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class HomeeButton(HomeeEntity, ButtonEntity):
|
||||||
|
"""Representation of a Homee button."""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
attribute: HomeeAttribute,
|
||||||
|
entry: HomeeConfigEntry,
|
||||||
|
description: ButtonEntityDescription,
|
||||||
|
) -> None:
|
||||||
|
"""Initialize a Homee button entity."""
|
||||||
|
super().__init__(attribute, entry)
|
||||||
|
self.entity_description = description
|
||||||
|
if attribute.instance == 0:
|
||||||
|
if attribute.type == AttributeType.IMPULSE:
|
||||||
|
self._attr_name = None
|
||||||
|
else:
|
||||||
|
self._attr_translation_key = description.key
|
||||||
|
else:
|
||||||
|
self._attr_translation_key = f"{description.key}_instance"
|
||||||
|
self._attr_translation_placeholders = {"instance": str(attribute.instance)}
|
||||||
|
|
||||||
|
async def async_press(self) -> None:
|
||||||
|
"""Handle the button press."""
|
||||||
|
await self.async_set_value(1)
|
@ -26,6 +26,41 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"entity": {
|
"entity": {
|
||||||
|
"button": {
|
||||||
|
"automatic_mode": {
|
||||||
|
"name": "Automatic mode"
|
||||||
|
},
|
||||||
|
"briefly_open": {
|
||||||
|
"name": "Briefly open"
|
||||||
|
},
|
||||||
|
"identification_mode": {
|
||||||
|
"name": "Identification mode"
|
||||||
|
},
|
||||||
|
"impulse_instance": {
|
||||||
|
"name": "Impulse {instance}"
|
||||||
|
},
|
||||||
|
"light": {
|
||||||
|
"name": "Light"
|
||||||
|
},
|
||||||
|
"light_instance": {
|
||||||
|
"name": "Light {instance}"
|
||||||
|
},
|
||||||
|
"open_partial": {
|
||||||
|
"name": "Open partially"
|
||||||
|
},
|
||||||
|
"permanently_open": {
|
||||||
|
"name": "Open permanently"
|
||||||
|
},
|
||||||
|
"reset_meter": {
|
||||||
|
"name": "Reset meter"
|
||||||
|
},
|
||||||
|
"reset_meter_instance": {
|
||||||
|
"name": "Reset meter {instance}"
|
||||||
|
},
|
||||||
|
"ventilate": {
|
||||||
|
"name": "Ventilate"
|
||||||
|
}
|
||||||
|
},
|
||||||
"sensor": {
|
"sensor": {
|
||||||
"brightness_instance": {
|
"brightness_instance": {
|
||||||
"name": "Illuminance {instance}"
|
"name": "Illuminance {instance}"
|
||||||
|
274
tests/components/homee/fixtures/buttons.json
Normal file
274
tests/components/homee/fixtures/buttons.json
Normal file
@ -0,0 +1,274 @@
|
|||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"name": "Test Button",
|
||||||
|
"profile": 2015,
|
||||||
|
"image": "default",
|
||||||
|
"favorite": 0,
|
||||||
|
"order": 1,
|
||||||
|
"protocol": 19,
|
||||||
|
"routing": 0,
|
||||||
|
"state": 1,
|
||||||
|
"state_changed": 1676561556,
|
||||||
|
"added": 1675835814,
|
||||||
|
"history": 1,
|
||||||
|
"cube_type": 17,
|
||||||
|
"note": "# Hörmann Garagentor Serie 3",
|
||||||
|
"services": 7,
|
||||||
|
"phonetic_name": "",
|
||||||
|
"owner": 2,
|
||||||
|
"security": 0,
|
||||||
|
"attributes": [
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 1.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 326,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1677692134,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 2,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 1.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 327,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1677692134,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 3,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 170,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1672148539,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 304,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1739125922,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 4,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 5,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 1,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 304,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1739125922,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 4,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 2,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 304,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1739125922,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 4,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 1.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 305,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1677692134,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 8,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 306,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1677692134,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 9,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 328,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1677692134,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 10,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 1,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 347,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1682166450,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 11,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 2,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 347,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1682166450,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 12,
|
||||||
|
"node_id": 1,
|
||||||
|
"instance": 0,
|
||||||
|
"minimum": 0,
|
||||||
|
"maximum": 1,
|
||||||
|
"current_value": 0.0,
|
||||||
|
"target_value": 0.0,
|
||||||
|
"last_value": 0.0,
|
||||||
|
"unit": "n/a",
|
||||||
|
"step_value": 1.0,
|
||||||
|
"editable": 1,
|
||||||
|
"type": 378,
|
||||||
|
"state": 1,
|
||||||
|
"last_changed": 1677692134,
|
||||||
|
"changed_by": 1,
|
||||||
|
"changed_by_id": 0,
|
||||||
|
"based_on": 1,
|
||||||
|
"data": "",
|
||||||
|
"name": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
566
tests/components/homee/snapshots/test_button.ambr
Normal file
566
tests/components/homee/snapshots/test_button.ambr
Normal file
@ -0,0 +1,566 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_button_snapshot[button.test_button-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': None,
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': '00055511EECC-1-4',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_automatic_mode-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_automatic_mode',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Automatic mode',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'automatic_mode',
|
||||||
|
'unique_id': '00055511EECC-1-1',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_automatic_mode-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Automatic mode',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_automatic_mode',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_briefly_open-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_briefly_open',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Briefly open',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'briefly_open',
|
||||||
|
'unique_id': '00055511EECC-1-2',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_briefly_open-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Briefly open',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_briefly_open',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_identification_mode-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||||
|
'entity_id': 'button.test_button_identification_mode',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <ButtonDeviceClass.IDENTIFY: 'identify'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Identification mode',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'identification_mode',
|
||||||
|
'unique_id': '00055511EECC-1-3',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_identification_mode-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'identify',
|
||||||
|
'friendly_name': 'Test Button Identification mode',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_identification_mode',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_impulse_1-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_impulse_1',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Impulse 1',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'impulse_instance',
|
||||||
|
'unique_id': '00055511EECC-1-5',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_impulse_1-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Impulse 1',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_impulse_1',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_impulse_2-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_impulse_2',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Impulse 2',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'impulse_instance',
|
||||||
|
'unique_id': '00055511EECC-1-6',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_impulse_2-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Impulse 2',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_impulse_2',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_light-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_light',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Light',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'light',
|
||||||
|
'unique_id': '00055511EECC-1-7',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_light-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Light',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_light',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_open_partially-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_open_partially',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Open partially',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'open_partial',
|
||||||
|
'unique_id': '00055511EECC-1-8',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_open_partially-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Open partially',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_open_partially',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_open_permanently-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_open_permanently',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Open permanently',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'permanently_open',
|
||||||
|
'unique_id': '00055511EECC-1-9',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_open_permanently-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Open permanently',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_open_permanently',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_reset_meter_1-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||||
|
'entity_id': 'button.test_button_reset_meter_1',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Reset meter 1',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'reset_meter_instance',
|
||||||
|
'unique_id': '00055511EECC-1-10',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_reset_meter_1-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Reset meter 1',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_reset_meter_1',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_reset_meter_2-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': <EntityCategory.CONFIG: 'config'>,
|
||||||
|
'entity_id': 'button.test_button_reset_meter_2',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Reset meter 2',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'reset_meter_instance',
|
||||||
|
'unique_id': '00055511EECC-1-11',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_reset_meter_2-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Reset meter 2',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_reset_meter_2',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_ventilate-entry]
|
||||||
|
EntityRegistryEntrySnapshot({
|
||||||
|
'aliases': set({
|
||||||
|
}),
|
||||||
|
'area_id': None,
|
||||||
|
'capabilities': None,
|
||||||
|
'config_entry_id': <ANY>,
|
||||||
|
'config_subentry_id': <ANY>,
|
||||||
|
'device_class': None,
|
||||||
|
'device_id': <ANY>,
|
||||||
|
'disabled_by': None,
|
||||||
|
'domain': 'button',
|
||||||
|
'entity_category': None,
|
||||||
|
'entity_id': 'button.test_button_ventilate',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'labels': set({
|
||||||
|
}),
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': None,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'Ventilate',
|
||||||
|
'platform': 'homee',
|
||||||
|
'previous_unique_id': None,
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': 'ventilate',
|
||||||
|
'unique_id': '00055511EECC-1-12',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_button_snapshot[button.test_button_ventilate-state]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'friendly_name': 'Test Button Ventilate',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'button.test_button_ventilate',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_reported': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'unknown',
|
||||||
|
})
|
||||||
|
# ---
|
50
tests/components/homee/test_button.py
Normal file
50
tests/components/homee/test_button.py
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
"""Test Homee buttons."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
|
from homeassistant.components.button import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS
|
||||||
|
from homeassistant.const import ATTR_ENTITY_ID, Platform
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.helpers import entity_registry as er
|
||||||
|
|
||||||
|
from . import build_mock_node, setup_integration
|
||||||
|
|
||||||
|
from tests.common import MockConfigEntry, snapshot_platform
|
||||||
|
|
||||||
|
|
||||||
|
async def test_button_press(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_homee: MagicMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test press button service."""
|
||||||
|
mock_homee.nodes = [build_mock_node("buttons.json")]
|
||||||
|
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
BUTTON_DOMAIN,
|
||||||
|
SERVICE_PRESS,
|
||||||
|
{ATTR_ENTITY_ID: "button.test_button_impulse_1"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
mock_homee.set_value.assert_called_once_with(1, 5, 1)
|
||||||
|
|
||||||
|
|
||||||
|
async def test_button_snapshot(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_homee: MagicMock,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
) -> None:
|
||||||
|
"""Test the multisensor snapshot."""
|
||||||
|
mock_homee.nodes = [build_mock_node("buttons.json")]
|
||||||
|
mock_homee.get_node_by_id.return_value = mock_homee.nodes[0]
|
||||||
|
with patch("homeassistant.components.homee.PLATFORMS", [Platform.BUTTON]):
|
||||||
|
await setup_integration(hass, mock_config_entry)
|
||||||
|
|
||||||
|
await snapshot_platform(hass, entity_registry, snapshot, mock_config_entry.entry_id)
|
Loading…
x
Reference in New Issue
Block a user