From 960b978d03e090289d0f4d1acfc8ed1b0457532c Mon Sep 17 00:00:00 2001 From: petretiandrea Date: Mon, 16 Oct 2023 20:08:58 +0000 Subject: [PATCH] restored siren for h100 --- custom_components/tapo/coordinators.py | 20 ++++++++++++-------- custom_components/tapo/hub/siren.py | 3 +-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/custom_components/tapo/coordinators.py b/custom_components/tapo/coordinators.py index ddffc47..4979eee 100644 --- a/custom_components/tapo/coordinators.py +++ b/custom_components/tapo/coordinators.py @@ -40,7 +40,7 @@ from plugp100.common.functional.tri import Failure from plugp100.common.functional.tri import Try from plugp100.responses.child_device_list import PowerStripChild -from plugp100.responses.device_state import DeviceInfo +from plugp100.responses.device_state import DeviceInfo as TapoDeviceInfo from plugp100.responses.device_state import LedStripDeviceState from plugp100.responses.device_state import LightDeviceState from plugp100.responses.device_state import PlugDeviceState @@ -64,7 +64,7 @@ class HassTapoDeviceData: async def create_coordinator( hass: HomeAssistant, client: TapoClient, host: str, polling_interval: timedelta ) -> Try["TapoCoordinator"]: - device_info = (await client.get_device_info()).map(lambda x: DeviceInfo(**x)) + device_info = (await client.get_device_info()).map(lambda x: TapoDeviceInfo(**x)) if device_info.is_success(): model = get_short_model(device_info.get().model) _LOGGER.info("Detected model of %s: %s", str(host), str(model)) @@ -130,8 +130,12 @@ def update_state_of(self, target_type: Type[T], state: Optional[T]) -> StateMap: return self._states @property - def device_info(self) -> DeviceInfo: - return self.get_state_of(DeviceInfo) + def model(self) -> str: + return self.get_state_of(TapoDeviceInfo).model.lower() + + @property + def device_info(self) -> TapoDeviceInfo: + return self.get_state_of(TapoDeviceInfo) @abstractmethod async def _update_state(self) -> None: @@ -168,7 +172,7 @@ def __init__( @cached_property def has_power_monitor(self) -> bool: return ( - get_short_model(self.get_state_of(DeviceInfo).model) + get_short_model(self.get_state_of(TapoDeviceInfo).model) in SUPPORTED_DEVICE_AS_SWITCH_POWER_MONITOR ) @@ -176,7 +180,7 @@ async def _update_state(self): plug = cast(PlugDevice, self.device) plug_state = (await plug.get_state()).get_or_raise() self.update_state_of(PlugDeviceState, plug_state) - self.update_state_of(DeviceInfo, plug_state.info) + self.update_state_of(TapoDeviceInfo, plug_state.info) if self.has_power_monitor: power_info = value_optional(await plug.get_current_power()) energy_usage = value_optional(await plug.get_energy_usage()) @@ -195,7 +199,7 @@ def __init__( async def _update_state(self): state = (await self.device.get_state()).get_or_raise() - self.update_state_of(DeviceInfo, state.info) + self.update_state_of(TapoDeviceInfo, state.info) if isinstance(self.device, LightDevice): self.update_state_of(LightDeviceState, state) elif isinstance(self.device, LedStripDevice): @@ -222,7 +226,7 @@ def __init__( async def _update_state(self): strip_state = (await self.device.get_state()).get_or_raise() children_state = (await self.device.get_children()).get_or_raise() - self.update_state_of(DeviceInfo, strip_state.info) + self.update_state_of(TapoDeviceInfo, strip_state.info) self.update_state_of(PowerStripChildrenState, children_state) def get_children(self) -> list[PowerStripChild]: diff --git a/custom_components/tapo/hub/siren.py b/custom_components/tapo/hub/siren.py index 97951ce..58cafe2 100644 --- a/custom_components/tapo/hub/siren.py +++ b/custom_components/tapo/hub/siren.py @@ -18,7 +18,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity from plugp100.requests.set_device_info.play_alarm_params import PlayAlarmParams -from plugp100.responses.device_state import DeviceInfo as TapoDeviceInfo from plugp100.responses.device_state import HubDeviceState @@ -26,7 +25,7 @@ async def async_setup_entry( hass: HomeAssistant, entry: ConfigEntry, async_add_devices: AddEntitiesCallback ): data = cast(HassTapoDeviceData, hass.data[DOMAIN][entry.entry_id]) - if data.coordinator.get_state_of(TapoDeviceInfo).model == SUPPORTED_HUB_ALARM: + if data.coordinator.model == SUPPORTED_HUB_ALARM: available_tones = ( (await data.coordinator.device.get_supported_alarm_tones()) .get_or_raise()