mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +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."""
|
"""Provides button entities for Home Connect."""
|
||||||
|
|
||||||
from aiohomeconnect.model import CommandKey, EventKey
|
from aiohomeconnect.model import CommandKey
|
||||||
from aiohomeconnect.model.error import HomeConnectError
|
from aiohomeconnect.model.error import HomeConnectError
|
||||||
|
|
||||||
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
from homeassistant.components.button import ButtonEntity, ButtonEntityDescription
|
||||||
@ -94,15 +94,9 @@ class HomeConnectButtonEntity(HomeConnectEntity, ButtonEntity):
|
|||||||
super().__init__(
|
super().__init__(
|
||||||
coordinator,
|
coordinator,
|
||||||
appliance,
|
appliance,
|
||||||
# The entity is subscribed to the appliance connected event,
|
desc,
|
||||||
# but it will receive also the disconnected event
|
(appliance.info.ha_id,),
|
||||||
ButtonEntityDescription(
|
|
||||||
key=EventKey.BSH_COMMON_APPLIANCE_CONNECTED,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
self.entity_description = desc
|
|
||||||
self.appliance = appliance
|
|
||||||
self._attr_unique_id = f"{appliance.info.ha_id}-{desc.key}"
|
|
||||||
|
|
||||||
def update_native_value(self) -> None:
|
def update_native_value(self) -> None:
|
||||||
"""Set the value of the entity."""
|
"""Set the value of the entity."""
|
||||||
|
@ -40,9 +40,13 @@ class HomeConnectEntity(CoordinatorEntity[HomeConnectCoordinator]):
|
|||||||
coordinator: HomeConnectCoordinator,
|
coordinator: HomeConnectCoordinator,
|
||||||
appliance: HomeConnectApplianceData,
|
appliance: HomeConnectApplianceData,
|
||||||
desc: EntityDescription,
|
desc: EntityDescription,
|
||||||
|
context_override: Any | None = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the entity."""
|
"""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.appliance = appliance
|
||||||
self.entity_description = desc
|
self.entity_description = desc
|
||||||
self._attr_unique_id = f"{appliance.info.ha_id}-{desc.key}"
|
self._attr_unique_id = f"{appliance.info.ha_id}-{desc.key}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user