mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Small cleanup in Tailwind (#106073)
This commit is contained in:
parent
64a2c64419
commit
63a535e9d9
@ -46,7 +46,7 @@ async def async_setup_entry(
|
||||
"""Set up Tailwind binary sensor based on a config entry."""
|
||||
coordinator: TailwindDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
async_add_entities(
|
||||
TailwindDoorBinarySensorEntity(coordinator, description, door_id)
|
||||
TailwindDoorBinarySensorEntity(coordinator, door_id, description)
|
||||
for description in DESCRIPTIONS
|
||||
for door_id in coordinator.data.doors
|
||||
)
|
||||
@ -57,19 +57,6 @@ class TailwindDoorBinarySensorEntity(TailwindDoorEntity, BinarySensorEntity):
|
||||
|
||||
entity_description: TailwindDoorBinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TailwindDataUpdateCoordinator,
|
||||
description: TailwindDoorBinarySensorEntityDescription,
|
||||
door_id: str,
|
||||
) -> None:
|
||||
"""Initiate Tailwind button entity."""
|
||||
super().__init__(coordinator, door_id)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = (
|
||||
f"{coordinator.data.device_id}-{door_id}-{description.key}"
|
||||
)
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return the state of the binary sensor."""
|
||||
|
@ -60,16 +60,6 @@ class TailwindButtonEntity(TailwindEntity, ButtonEntity):
|
||||
|
||||
entity_description: TailwindButtonEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TailwindDataUpdateCoordinator,
|
||||
description: TailwindButtonEntityDescription,
|
||||
) -> None:
|
||||
"""Initiate Tailwind button entity."""
|
||||
super().__init__(coordinator=coordinator)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{coordinator.data.device_id}-{description.key}"
|
||||
|
||||
async def async_press(self) -> None:
|
||||
"""Trigger button press on the Tailwind device."""
|
||||
await self.entity_description.press_fn(self.coordinator.tailwind)
|
||||
|
@ -41,15 +41,6 @@ class TailwindDoorCoverEntity(TailwindDoorEntity, CoverEntity):
|
||||
_attr_name = None
|
||||
_attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TailwindDataUpdateCoordinator,
|
||||
door_id: str,
|
||||
) -> None:
|
||||
"""Initiate Tailwind button entity."""
|
||||
super().__init__(coordinator, door_id)
|
||||
self._attr_unique_id = f"{coordinator.data.device_id}-{door_id}"
|
||||
|
||||
@property
|
||||
def is_closed(self) -> bool:
|
||||
"""Return if the cover is closed or not."""
|
||||
|
@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.helpers.device_registry import CONNECTION_NETWORK_MAC, DeviceInfo
|
||||
from homeassistant.helpers.entity import EntityDescription
|
||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
|
||||
from .const import DOMAIN
|
||||
@ -13,9 +14,15 @@ class TailwindEntity(CoordinatorEntity[TailwindDataUpdateCoordinator]):
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, coordinator: TailwindDataUpdateCoordinator) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TailwindDataUpdateCoordinator,
|
||||
entity_description: EntityDescription,
|
||||
) -> None:
|
||||
"""Initialize an Tailwind entity."""
|
||||
super().__init__(coordinator)
|
||||
self.entity_description = entity_description
|
||||
self._attr_unique_id = f"{coordinator.data.device_id}-{entity_description.key}"
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, coordinator.data.device_id)},
|
||||
connections={(CONNECTION_NETWORK_MAC, coordinator.data.mac_address)},
|
||||
@ -35,11 +42,22 @@ class TailwindDoorEntity(CoordinatorEntity[TailwindDataUpdateCoordinator]):
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(
|
||||
self, coordinator: TailwindDataUpdateCoordinator, door_id: str
|
||||
self,
|
||||
coordinator: TailwindDataUpdateCoordinator,
|
||||
door_id: str,
|
||||
entity_description: EntityDescription | None = None,
|
||||
) -> None:
|
||||
"""Initialize an Tailwind door entity."""
|
||||
self.door_id = door_id
|
||||
super().__init__(coordinator)
|
||||
self.door_id = door_id
|
||||
|
||||
self._attr_unique_id = f"{coordinator.data.device_id}-{door_id}"
|
||||
if entity_description:
|
||||
self.entity_description = entity_description
|
||||
self._attr_unique_id = (
|
||||
f"{coordinator.data.device_id}-{door_id}-{entity_description.key}"
|
||||
)
|
||||
|
||||
self._attr_device_info = DeviceInfo(
|
||||
identifiers={(DOMAIN, f"{coordinator.data.device_id}-{door_id}")},
|
||||
via_device=(DOMAIN, coordinator.data.device_id),
|
||||
|
@ -65,16 +65,6 @@ class TailwindNumberEntity(TailwindEntity, NumberEntity):
|
||||
|
||||
entity_description: TailwindNumberEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
coordinator: TailwindDataUpdateCoordinator,
|
||||
description: TailwindNumberEntityDescription,
|
||||
) -> None:
|
||||
"""Initiate Tailwind number entity."""
|
||||
super().__init__(coordinator)
|
||||
self.entity_description = description
|
||||
self._attr_unique_id = f"{coordinator.data.device_id}-{description.key}"
|
||||
|
||||
@property
|
||||
def native_value(self) -> int | None:
|
||||
"""Return the number value."""
|
||||
|
@ -143,3 +143,147 @@
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_1_operational_status]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Door 1 Operational status',
|
||||
'icon': 'mdi:garage-alert',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.door_1_operational_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_1_operational_status].1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.door_1_operational_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:garage-alert',
|
||||
'original_name': 'Operational status',
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'operational_status',
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-door1-locked_out',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_1_operational_status].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_-door1',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'name': 'Door 1',
|
||||
'name_by_user': None,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_2_operational_status]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'friendly_name': 'Door 2 Operational status',
|
||||
'icon': 'mdi:garage-alert',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.door_2_operational_status',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_2_operational_status].1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.door_2_operational_status',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': None,
|
||||
'original_icon': 'mdi:garage-alert',
|
||||
'original_name': 'Operational status',
|
||||
'platform': 'tailwind',
|
||||
'previous_unique_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': 'operational_status',
|
||||
'unique_id': '_3c_e9_e_6d_21_84_-door2-locked_out',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_number_entities[binary_sensor.door_2_operational_status].2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': None,
|
||||
'connections': set({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': None,
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'tailwind',
|
||||
'_3c_e9_e_6d_21_84_-door2',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'Tailwind',
|
||||
'model': 'iQ3',
|
||||
'name': 'Door 2',
|
||||
'name_by_user': None,
|
||||
'serial_number': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '10.10',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
||||
|
@ -9,23 +9,27 @@ from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"entity_id",
|
||||
[
|
||||
"binary_sensor.door_1_operational_status",
|
||||
"binary_sensor.door_2_operational_status",
|
||||
],
|
||||
)
|
||||
async def test_number_entities(
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
entity_id: str,
|
||||
) -> None:
|
||||
"""Test binary sensor entities provided by the Tailwind integration."""
|
||||
for entity_id in (
|
||||
"binary_sensor.door_1_operational_status",
|
||||
"binary_sensor.door_2_operational_status",
|
||||
):
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert snapshot == state
|
||||
assert (state := hass.states.get(entity_id))
|
||||
assert snapshot == state
|
||||
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert snapshot == entity_entry
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert snapshot == entity_entry
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert snapshot == device_entry
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert snapshot == device_entry
|
||||
|
Loading…
x
Reference in New Issue
Block a user