From ec24b93c1782b0dcf9882f34d44ac98c154cff95 Mon Sep 17 00:00:00 2001 From: Anton Malko Date: Mon, 5 Dec 2022 05:31:35 +0300 Subject: [PATCH] Bump aiolookin to 1.0.0 (#83198) Co-authored-by: J. Nick Koston --- homeassistant/components/lookin/__init__.py | 32 ++++++++++--------- homeassistant/components/lookin/climate.py | 31 ++++++++++++------ homeassistant/components/lookin/entity.py | 5 +-- homeassistant/components/lookin/manifest.json | 2 +- .../components/lookin/media_player.py | 24 ++++++++++++++ homeassistant/components/lookin/models.py | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 8 files changed, 69 insertions(+), 31 deletions(-) diff --git a/homeassistant/components/lookin/__init__.py b/homeassistant/components/lookin/__init__.py index 5ab4078eb20..189e5c6271e 100644 --- a/homeassistant/components/lookin/__init__.py +++ b/homeassistant/components/lookin/__init__.py @@ -101,16 +101,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: push_coordinator = LookinPushCoordinator(entry.title) - meteo_coordinator: LookinDataUpdateCoordinator = LookinDataUpdateCoordinator( - hass, - push_coordinator, - name=entry.title, - update_method=lookin_protocol.get_meteo_sensor, - update_interval=timedelta( - minutes=5 - ), # Updates are pushed (fallback is polling) - ) - await meteo_coordinator.async_config_entry_first_refresh() + if lookin_device.model >= 2: + meteo_coordinator: LookinDataUpdateCoordinator = LookinDataUpdateCoordinator( + hass, + push_coordinator, + name=entry.title, + update_method=lookin_protocol.get_meteo_sensor, + update_interval=timedelta( + minutes=5 + ), # Updates are pushed (fallback is polling) + ) + await meteo_coordinator.async_config_entry_first_refresh() device_coordinators: dict[str, LookinDataUpdateCoordinator] = {} for remote in devices: @@ -148,17 +149,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: lookin_udp_subs = await manager.async_get_subscriptions() - entry.async_on_unload( - lookin_udp_subs.subscribe_event( - lookin_device.id, UDPCommandType.meteo, None, _async_meteo_push_update + if lookin_device.model >= 2: + entry.async_on_unload( + lookin_udp_subs.subscribe_event( + lookin_device.id, UDPCommandType.meteo, None, _async_meteo_push_update + ) ) - ) hass.data[DOMAIN][entry.entry_id] = LookinData( host=host, lookin_udp_subs=lookin_udp_subs, lookin_device=lookin_device, - meteo_coordinator=meteo_coordinator, + meteo_coordinator=meteo_coordinator if lookin_device.model >= 2 else None, devices=devices, lookin_protocol=lookin_protocol, device_coordinators=device_coordinators, diff --git a/homeassistant/components/lookin/climate.py b/homeassistant/components/lookin/climate.py index aa3ba0c3614..46c6623e5b7 100644 --- a/homeassistant/components/lookin/climate.py +++ b/homeassistant/components/lookin/climate.py @@ -146,13 +146,18 @@ class ConditionerEntity(LookinCoordinatorEntity, ClimateEntity): # or cool otherwise we set auto since we don't have a way to make # an educated guess. # - meteo_data: MeteoSensor = self._meteo_coordinator.data - if not (current_temp := meteo_data.temperature): - self._climate.hvac_mode = lookin_index.index(HVACMode.AUTO) - elif current_temp >= self._climate.temp_celsius: - self._climate.hvac_mode = lookin_index.index(HVACMode.COOL) + + if self._meteo_coordinator: + meteo_data: MeteoSensor = self._meteo_coordinator.data + if not (current_temp := meteo_data.temperature): + self._climate.hvac_mode = lookin_index.index(HVACMode.AUTO) + elif current_temp >= self._climate.temp_celsius: + self._climate.hvac_mode = lookin_index.index(HVACMode.COOL) + else: + self._climate.hvac_mode = lookin_index.index(HVACMode.HEAT) else: - self._climate.hvac_mode = lookin_index.index(HVACMode.HEAT) + self._climate.hvac_mode = lookin_index.index(HVACMode.AUTO) + await self._async_update_conditioner() async def async_set_fan_mode(self, fan_mode: str) -> None: @@ -172,14 +177,20 @@ class ConditionerEntity(LookinCoordinatorEntity, ClimateEntity): async def _async_update_conditioner(self) -> None: """Update the conditioner state from the climate data.""" self.coordinator.async_set_updated_data(self._climate) - await self._lookin_protocol.update_conditioner(climate=self._climate) + await self._lookin_protocol.update_conditioner( + uuid=self._attr_unique_id, status=self._climate.to_status + ) def _async_update_from_data(self) -> None: """Update attrs from data.""" - meteo_data: MeteoSensor = self._meteo_coordinator.data + if self._meteo_coordinator: + temperature = self._meteo_coordinator.data.temperature + humidity = int(self._meteo_coordinator.data.humidity) + else: + temperature = humidity = None - self._attr_current_temperature = meteo_data.temperature - self._attr_current_humidity = int(meteo_data.humidity) + self._attr_current_temperature = temperature + self._attr_current_humidity = humidity self._attr_target_temperature = self._climate.temp_celsius self._attr_fan_mode = LOOKIN_FAN_MODE_IDX_TO_HASS[self._climate.fan_mode] self._attr_swing_mode = LOOKIN_SWING_MODE_IDX_TO_HASS[self._climate.swing_mode] diff --git a/homeassistant/components/lookin/entity.py b/homeassistant/components/lookin/entity.py index 1c641b76f32..04605d9db6c 100644 --- a/homeassistant/components/lookin/entity.py +++ b/homeassistant/components/lookin/entity.py @@ -61,6 +61,7 @@ class LookinDeviceCoordinatorEntity( def __init__(self, lookin_data: LookinData) -> None: """Init the lookin device entity.""" + assert lookin_data.meteo_coordinator is not None super().__init__(lookin_data.meteo_coordinator) self._set_lookin_device_attrs(lookin_data) self._attr_device_info = _lookin_device_to_device_info( @@ -109,10 +110,10 @@ class LookinCoordinatorEntity( self._attr_unique_id = uuid self._attr_name = device.name - async def _async_send_command(self, command: str) -> None: + async def _async_send_command(self, command: str, signal: str = "FF") -> None: """Send command from saved IR device.""" await self._lookin_protocol.send_command( - uuid=self._uuid, command=command, signal="FF" + uuid=self._uuid, command=command, signal=signal ) diff --git a/homeassistant/components/lookin/manifest.json b/homeassistant/components/lookin/manifest.json index b58eb254f8f..d6e1cd13686 100644 --- a/homeassistant/components/lookin/manifest.json +++ b/homeassistant/components/lookin/manifest.json @@ -3,7 +3,7 @@ "name": "LOOKin", "documentation": "https://www.home-assistant.io/integrations/lookin/", "codeowners": ["@ANMalko", "@bdraco"], - "requirements": ["aiolookin==0.1.1"], + "requirements": ["aiolookin==1.0.0"], "zeroconf": ["_lookin._tcp.local."], "config_flow": true, "iot_class": "local_push", diff --git a/homeassistant/components/lookin/media_player.py b/homeassistant/components/lookin/media_player.py index 9e925836e11..405852e88a6 100644 --- a/homeassistant/components/lookin/media_player.py +++ b/homeassistant/components/lookin/media_player.py @@ -36,6 +36,7 @@ _FUNCTION_NAME_TO_FEATURE = { "volup": MediaPlayerEntityFeature.VOLUME_STEP, "chup": MediaPlayerEntityFeature.NEXT_TRACK, "chdown": MediaPlayerEntityFeature.PREVIOUS_TRACK, + "mode": MediaPlayerEntityFeature.SELECT_SOURCE, } @@ -86,6 +87,29 @@ class LookinMedia(LookinPowerPushRemoteEntity, MediaPlayerEntity): for function_name, feature in _FUNCTION_NAME_TO_FEATURE.items(): if function_name in self._function_names: self._attr_supported_features |= feature + self._source_list: dict[str, str] | None = None + + @property + def source_list(self) -> list[str]: + """List of available input sources.""" + return list(self._source_list.keys()) if self._source_list else [] + + async def async_select_source(self, source: str) -> None: + """Choose an available playlist and play it.""" + if not self._source_list: + return + await self._async_send_command(command="mode", signal=self._source_list[source]) + + async def async_added_to_hass(self) -> None: + """Get list of available input sources.""" + if self._source_list is None and "mode" in self._function_names: + if sources := await self._lookin_protocol.get_media_sources( + uuid=self._uuid + ): + self._source_list = { + f"INPUT_{index}": f"{index:02x}" for index in range(len(sources)) + } + await super().async_added_to_hass() async def async_volume_up(self) -> None: """Turn volume up for media player.""" diff --git a/homeassistant/components/lookin/models.py b/homeassistant/components/lookin/models.py index f0dffe66ec0..c89d8057218 100644 --- a/homeassistant/components/lookin/models.py +++ b/homeassistant/components/lookin/models.py @@ -16,7 +16,7 @@ class LookinData: host: str lookin_udp_subs: LookinUDPSubscriptions lookin_device: Device - meteo_coordinator: LookinDataUpdateCoordinator + meteo_coordinator: LookinDataUpdateCoordinator | None devices: list[dict[str, Any]] lookin_protocol: LookInHttpProtocol device_coordinators: dict[str, LookinDataUpdateCoordinator] diff --git a/requirements_all.txt b/requirements_all.txt index 6f84f332528..35c6ba91c5b 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -205,7 +205,7 @@ aiolifx_themes==0.2.0 aiolivisi==0.0.14 # homeassistant.components.lookin -aiolookin==0.1.1 +aiolookin==1.0.0 # homeassistant.components.lyric aiolyric==1.0.9 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 987c3dacf11..c43558c342f 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -183,7 +183,7 @@ aiolifx_themes==0.2.0 aiolivisi==0.0.14 # homeassistant.components.lookin -aiolookin==0.1.1 +aiolookin==1.0.0 # homeassistant.components.lyric aiolyric==1.0.9