mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 09:17:53 +00:00
Add coordinator context override to Home Connect entity constructor (#141104)
* Improve Home Connect entity constructor to allow coordinator context override * Simplify context usage at entity constructor
This commit is contained in:
parent
9d9b352631
commit
dc146e393c
@ -1,6 +1,6 @@
|
||||
"""Provides button entities for Home Connect."""
|
||||
|
||||
from aiohomeconnect.model import CommandKey, EventKey
|
||||
from aiohomeconnect.model import CommandKey
|
||||
from aiohomeconnect.model.error import HomeConnectError
|
||||
|
||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||
@ -94,15 +94,9 @@ class HomeConnectButtonEntity(HomeConnectEntity, ButtonEntity):
|
||||
super().__init__(
|
||||
coordinator,
|
||||
appliance,
|
||||
# The entity is subscribed to the appliance connected event,
|
||||
# but it will receive also the disconnected event
|
||||
ButtonEntityDescription(
|
||||
key=EventKey.BSH_COMMON_APPLIANCE_CONNECTED,
|
||||
),
|
||||
desc,
|
||||
(appliance.info.ha_id,),
|
||||
)
|
||||
self.entity_description = desc
|
||||
self.appliance = appliance
|
||||
self._attr_unique_id = f"{appliance.info.ha_id}-{desc.key}"
|
||||
|
||||
def update_native_value(self) -> None:
|
||||
"""Set the value of the entity."""
|
||||
|
@ -40,9 +40,13 @@ class HomeConnectEntity(CoordinatorEntity[HomeConnectCoordinator]):
|
||||
coordinator: HomeConnectCoordinator,
|
||||
appliance: HomeConnectApplianceData,
|
||||
desc: EntityDescription,
|
||||
context_override: Any | None = None,
|
||||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
super().__init__(coordinator, (appliance.info.ha_id, EventKey(desc.key)))
|
||||
context = (appliance.info.ha_id, EventKey(desc.key))
|
||||
if context_override is not None:
|
||||
context = context_override
|
||||
super().__init__(coordinator, context)
|
||||
self.appliance = appliance
|
||||
self.entity_description = desc
|
||||
self._attr_unique_id = f"{appliance.info.ha_id}-{desc.key}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user