Add non coordinated Entity to Roborock (#93841)
switch to non coordinator entity
This commit is contained in:
parent
8cd8355ab1
commit
81561d4d3e
3 changed files with 52 additions and 36 deletions
|
@ -15,7 +15,7 @@ from homeassistant.util import slugify
|
|||
|
||||
from .const import DOMAIN
|
||||
from .coordinator import RoborockDataUpdateCoordinator
|
||||
from .device import RoborockCoordinatedEntity
|
||||
from .device import RoborockEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -25,11 +25,11 @@ class RoborockSwitchDescriptionMixin:
|
|||
"""Define an entity description mixin for switch entities."""
|
||||
|
||||
# Gets the status of the switch
|
||||
get_value: Callable[[RoborockCoordinatedEntity], Coroutine[Any, Any, dict]]
|
||||
get_value: Callable[[RoborockEntity], Coroutine[Any, Any, dict]]
|
||||
# Evaluate the result of get_value to determine a bool
|
||||
evaluate_value: Callable[[dict], bool]
|
||||
# Sets the status of the switch
|
||||
set_command: Callable[[RoborockCoordinatedEntity, bool], Coroutine[Any, Any, dict]]
|
||||
set_command: Callable[[RoborockEntity, bool], Coroutine[Any, Any, dict]]
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -78,7 +78,7 @@ async def async_setup_entry(
|
|||
)
|
||||
|
||||
|
||||
class RoborockSwitchEntity(RoborockCoordinatedEntity, SwitchEntity):
|
||||
class RoborockSwitchEntity(RoborockEntity, SwitchEntity):
|
||||
"""A class to let you turn functionality on Roborock devices on and off."""
|
||||
|
||||
entity_description: RoborockSwitchDescription
|
||||
|
@ -91,17 +91,15 @@ class RoborockSwitchEntity(RoborockCoordinatedEntity, SwitchEntity):
|
|||
) -> None:
|
||||
"""Create a switch entity."""
|
||||
self.entity_description = entity_description
|
||||
super().__init__(unique_id, coordinator)
|
||||
super().__init__(unique_id, coordinator.device_specification, coordinator.api)
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
"""Turn off the switch."""
|
||||
await self.entity_description.set_command(self, False)
|
||||
return self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
"""Turn on the switch."""
|
||||
await self.entity_description.set_command(self, True)
|
||||
return self.async_schedule_update_ha_state(True)
|
||||
|
||||
async def async_update(self) -> None:
|
||||
"""Update switch."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue