mirror of
https://github.com/Andre0512/hon.git
synced 2025-05-21 18:35:10 -04:00
Rebuild to single data coordinator
This commit is contained in:
parent
8f1fc627e6
commit
a6c2c3e992
16 changed files with 148 additions and 203 deletions
|
@ -13,7 +13,8 @@ from pyhon.parameter.base import HonParameter
|
|||
from pyhon.parameter.range import HonParameterRange
|
||||
|
||||
from .const import DOMAIN
|
||||
from .hon import HonEntity, unique_entities
|
||||
from .entity import HonEntity
|
||||
from .util import unique_entities
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -406,7 +407,7 @@ async def async_setup_entry(
|
|||
) -> None:
|
||||
entities = []
|
||||
entity: HonConfigSwitchEntity | HonControlSwitchEntity | HonSwitchEntity
|
||||
for device in hass.data[DOMAIN][entry.unique_id].appliances:
|
||||
for device in hass.data[DOMAIN][entry.unique_id]["hon"].appliances:
|
||||
for description in SWITCHES.get(device.appliance_type, []):
|
||||
if isinstance(description, HonConfigSwitchEntityDescription):
|
||||
if description.key not in device.available_settings:
|
||||
|
@ -446,7 +447,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
|||
setting.value = setting.max if isinstance(setting, HonParameterRange) else 1
|
||||
self.async_write_ha_state()
|
||||
await self._device.commands["settings"].send()
|
||||
await self.coordinator.async_refresh()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
setting = self._device.settings[f"settings.{self.entity_description.key}"]
|
||||
|
@ -455,7 +456,7 @@ class HonSwitchEntity(HonEntity, SwitchEntity):
|
|||
setting.value = setting.min if isinstance(setting, HonParameterRange) else 0
|
||||
self.async_write_ha_state()
|
||||
await self._device.commands["settings"].send()
|
||||
await self.coordinator.async_refresh()
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
|
@ -488,14 +489,14 @@ class HonControlSwitchEntity(HonEntity, SwitchEntity):
|
|||
|
||||
async def async_turn_on(self, **kwargs: Any) -> None:
|
||||
self._device.sync_command(self.entity_description.turn_on_key, "settings")
|
||||
await self.coordinator.async_refresh()
|
||||
self.async_write_ha_state()
|
||||
await self._device.commands[self.entity_description.turn_on_key].send()
|
||||
self._device.attributes[self.entity_description.key] = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
self._device.sync_command(self.entity_description.turn_off_key, "settings")
|
||||
await self.coordinator.async_refresh()
|
||||
self.async_write_ha_state()
|
||||
await self._device.commands[self.entity_description.turn_off_key].send()
|
||||
self._device.attributes[self.entity_description.key] = False
|
||||
self.async_write_ha_state()
|
||||
|
@ -541,7 +542,7 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
|
|||
return
|
||||
setting.value = setting.max if isinstance(setting, HonParameterRange) else "1"
|
||||
self.async_write_ha_state()
|
||||
await self.coordinator.async_refresh()
|
||||
self.async_write_ha_state()
|
||||
|
||||
async def async_turn_off(self, **kwargs: Any) -> None:
|
||||
setting = self._device.settings[self.entity_description.key]
|
||||
|
@ -549,7 +550,7 @@ class HonConfigSwitchEntity(HonEntity, SwitchEntity):
|
|||
return
|
||||
setting.value = setting.min if isinstance(setting, HonParameterRange) else "0"
|
||||
self.async_write_ha_state()
|
||||
await self.coordinator.async_refresh()
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def _handle_coordinator_update(self, update: bool = True) -> None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue