Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restored siren for h100 #575

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions custom_components/tapo/coordinators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -168,15 +172,15 @@ 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
)

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())
Expand All @@ -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):
Expand All @@ -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]:
Expand Down
3 changes: 1 addition & 2 deletions custom_components/tapo/hub/siren.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
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


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()
Expand Down