From 8d99a546565b09e1b99d9f90a7d7df51b5a0aa3d Mon Sep 17 00:00:00 2001 From: Shay Levy Date: Mon, 20 Jan 2025 20:31:45 +0200 Subject: [PATCH] Bump aiowebostv to 0.5.0 (#136097) --- homeassistant/components/webostv/config_flow.py | 13 ++++--------- homeassistant/components/webostv/helpers.py | 6 ++++-- homeassistant/components/webostv/manifest.json | 2 +- homeassistant/components/webostv/media_player.py | 14 +++++--------- .../components/webostv/quality_scale.yaml | 4 +--- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/webostv/test_media_player.py | 6 +++--- 8 files changed, 20 insertions(+), 29 deletions(-) diff --git a/homeassistant/components/webostv/config_flow.py b/homeassistant/components/webostv/config_flow.py index a0ee9f1ac7f..6086fad8afd 100644 --- a/homeassistant/components/webostv/config_flow.py +++ b/homeassistant/components/webostv/config_flow.py @@ -9,12 +9,7 @@ from urllib.parse import urlparse from aiowebostv import WebOsTvPairError import voluptuous as vol -from homeassistant.config_entries import ( - ConfigEntry, - ConfigFlow, - ConfigFlowResult, - OptionsFlow, -) +from homeassistant.config_entries import ConfigFlow, ConfigFlowResult, OptionsFlow from homeassistant.const import CONF_CLIENT_SECRET, CONF_HOST from homeassistant.core import callback from homeassistant.helpers import config_validation as cv @@ -24,7 +19,7 @@ from homeassistant.helpers.service_info.ssdp import ( SsdpServiceInfo, ) -from . import async_control_connect +from . import WebOsTvConfigEntry, async_control_connect from .const import CONF_SOURCES, DEFAULT_NAME, DOMAIN, WEBOSTV_EXCEPTIONS from .helpers import async_get_sources @@ -49,7 +44,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN): @staticmethod @callback - def async_get_options_flow(config_entry: ConfigEntry) -> OptionsFlow: + def async_get_options_flow(config_entry: WebOsTvConfigEntry) -> OptionsFlow: """Get the options flow for this handler.""" return OptionsFlowHandler(config_entry) @@ -186,7 +181,7 @@ class FlowHandler(ConfigFlow, domain=DOMAIN): class OptionsFlowHandler(OptionsFlow): """Handle options.""" - def __init__(self, config_entry: ConfigEntry) -> None: + def __init__(self, config_entry: WebOsTvConfigEntry) -> None: """Initialize options flow.""" self.host = config_entry.data[CONF_HOST] self.key = config_entry.data[CONF_CLIENT_SECRET] diff --git a/homeassistant/components/webostv/helpers.py b/homeassistant/components/webostv/helpers.py index 63724069f17..3aea860798a 100644 --- a/homeassistant/components/webostv/helpers.py +++ b/homeassistant/components/webostv/helpers.py @@ -9,7 +9,7 @@ from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.device_registry import DeviceEntry -from . import async_control_connect +from . import WebOsTvConfigEntry, async_control_connect from .const import DOMAIN, LIVE_TV_APP_ID, WEBOSTV_EXCEPTIONS @@ -56,7 +56,9 @@ def async_get_client_by_device_entry( Raises ValueError if client is not found. """ for config_entry_id in device.config_entries: - entry = hass.config_entries.async_get_entry(config_entry_id) + entry: WebOsTvConfigEntry | None = hass.config_entries.async_get_entry( + config_entry_id + ) if entry and entry.domain == DOMAIN: if entry.state is ConfigEntryState.LOADED: return entry.runtime_data diff --git a/homeassistant/components/webostv/manifest.json b/homeassistant/components/webostv/manifest.json index 6c826c2f997..627bb83572c 100644 --- a/homeassistant/components/webostv/manifest.json +++ b/homeassistant/components/webostv/manifest.json @@ -6,7 +6,7 @@ "documentation": "https://www.home-assistant.io/integrations/webostv", "iot_class": "local_push", "loggers": ["aiowebostv"], - "requirements": ["aiowebostv==0.4.2"], + "requirements": ["aiowebostv==0.5.0"], "ssdp": [ { "st": "urn:lge-com:service:webos-second-screen:1" diff --git a/homeassistant/components/webostv/media_player.py b/homeassistant/components/webostv/media_player.py index 719e3edbf4b..a03449a49b6 100644 --- a/homeassistant/components/webostv/media_player.py +++ b/homeassistant/components/webostv/media_player.py @@ -196,7 +196,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): self._attr_volume_level = None if self._client.volume is not None: - self._attr_volume_level = cast(float, self._client.volume / 100.0) + self._attr_volume_level = self._client.volume / 100.0 self._attr_source = self._current_source self._attr_source_list = sorted(self._source_list) @@ -240,13 +240,9 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): ) self._attr_assumed_state = True - if ( - self._client.is_on - and self._client.media_state is not None - and self._client.media_state.get("foregroundAppInfo") is not None - ): + if self._client.is_on and self._client.media_state: self._attr_assumed_state = False - for entry in self._client.media_state.get("foregroundAppInfo"): + for entry in self._client.media_state: if entry.get("playState") == "playing": self._attr_state = MediaPlayerState.PLAYING elif entry.get("playState") == "paused": @@ -254,7 +250,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): elif entry.get("playState") == "unloaded": self._attr_state = MediaPlayerState.IDLE - if self._client.system_info is not None or self.state != MediaPlayerState.OFF: + if self.state != MediaPlayerState.OFF: maj_v = self._client.software_info.get("major_ver") min_v = self._client.software_info.get("minor_ver") if maj_v and min_v: @@ -406,7 +402,7 @@ class LgWebOSMediaPlayerEntity(RestoreEntity, MediaPlayerEntity): """Play a piece of media.""" _LOGGER.debug("Call play media type <%s>, Id <%s>", media_type, media_id) - if media_type == MediaType.CHANNEL: + if media_type == MediaType.CHANNEL and self._client.channels: _LOGGER.debug("Searching channel") partial_match_channel_id = None perfect_match_channel_id = None diff --git a/homeassistant/components/webostv/quality_scale.yaml b/homeassistant/components/webostv/quality_scale.yaml index 3a31c20f256..1b3a3173ffa 100644 --- a/homeassistant/components/webostv/quality_scale.yaml +++ b/homeassistant/components/webostv/quality_scale.yaml @@ -77,6 +77,4 @@ rules: inject-websession: status: todo comment: need to check if it is needed for websockets or migrate to aiohttp - strict-typing: - status: todo - comment: aiowebostv is not fully typed + strict-typing: done diff --git a/requirements_all.txt b/requirements_all.txt index 516cfc40864..235e8c6ce86 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -416,7 +416,7 @@ aiowaqi==3.1.0 aiowatttime==0.1.1 # homeassistant.components.webostv -aiowebostv==0.4.2 +aiowebostv==0.5.0 # homeassistant.components.withings aiowithings==3.1.4 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d4ac1bfac47..e902b44f154 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -398,7 +398,7 @@ aiowaqi==3.1.0 aiowatttime==0.1.1 # homeassistant.components.webostv -aiowebostv==0.4.2 +aiowebostv==0.5.0 # homeassistant.components.withings aiowithings==3.1.4 diff --git a/tests/components/webostv/test_media_player.py b/tests/components/webostv/test_media_player.py index 7dea412f4fa..ab3feac1f2d 100644 --- a/tests/components/webostv/test_media_player.py +++ b/tests/components/webostv/test_media_player.py @@ -820,15 +820,15 @@ async def test_update_media_state(hass: HomeAssistant, client) -> None: """Test updating media state.""" await setup_webostv(hass) - client.media_state = {"foregroundAppInfo": [{"playState": "playing"}]} + client.media_state = [{"playState": "playing"}] await client.mock_state_update() assert hass.states.get(ENTITY_ID).state == MediaPlayerState.PLAYING - client.media_state = {"foregroundAppInfo": [{"playState": "paused"}]} + client.media_state = [{"playState": "paused"}] await client.mock_state_update() assert hass.states.get(ENTITY_ID).state == MediaPlayerState.PAUSED - client.media_state = {"foregroundAppInfo": [{"playState": "unloaded"}]} + client.media_state = [{"playState": "unloaded"}] await client.mock_state_update() assert hass.states.get(ENTITY_ID).state == MediaPlayerState.IDLE