Improve vizio typing (#108042)

This commit is contained in:
Marc Mueller 2024-01-23 21:20:15 +01:00 committed by GitHub
parent 37f5c75752
commit a6807b8a7f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 15 deletions

View File

@ -67,7 +67,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
CONF_APPS not in hass.data[DOMAIN] CONF_APPS not in hass.data[DOMAIN]
and entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV and entry.data[CONF_DEVICE_CLASS] == MediaPlayerDeviceClass.TV
): ):
store: Store = Store(hass, 1, DOMAIN) store: Store[list[dict[str, Any]]] = Store(hass, 1, DOMAIN)
coordinator = VizioAppsDataUpdateCoordinator(hass, store) coordinator = VizioAppsDataUpdateCoordinator(hass, store)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()
hass.data[DOMAIN][CONF_APPS] = coordinator hass.data[DOMAIN][CONF_APPS] = coordinator
@ -100,7 +100,7 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
class VizioAppsDataUpdateCoordinator(DataUpdateCoordinator[list[dict[str, Any]]]): class VizioAppsDataUpdateCoordinator(DataUpdateCoordinator[list[dict[str, Any]]]):
"""Define an object to hold Vizio app config data.""" """Define an object to hold Vizio app config data."""
def __init__(self, hass: HomeAssistant, store: Store) -> None: def __init__(self, hass: HomeAssistant, store: Store[list[dict[str, Any]]]) -> None:
"""Initialize.""" """Initialize."""
super().__init__( super().__init__(
hass, hass,

View File

@ -188,8 +188,8 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Initialize config flow.""" """Initialize config flow."""
self._user_schema = None self._user_schema = None
self._must_show_form: bool | None = None self._must_show_form: bool | None = None
self._ch_type = None self._ch_type: str | None = None
self._pairing_token = None self._pairing_token: str | None = None
self._data: dict[str, Any] | None = None self._data: dict[str, Any] | None = None
self._apps: dict[str, list] = {} self._apps: dict[str, list] = {}
@ -208,7 +208,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
) -> FlowResult: ) -> FlowResult:
"""Handle a flow initialized by the user.""" """Handle a flow initialized by the user."""
errors = {} errors: dict[str, str] = {}
if user_input is not None: if user_input is not None:
# Store current values in case setup fails and user needs to edit # Store current values in case setup fails and user needs to edit
@ -294,8 +294,8 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
if await self.hass.async_add_executor_job( if await self.hass.async_add_executor_job(
_host_is_same, entry.data[CONF_HOST], import_config[CONF_HOST] _host_is_same, entry.data[CONF_HOST], import_config[CONF_HOST]
): ):
updated_options = {} updated_options: dict[str, Any] = {}
updated_data = {} updated_data: dict[str, Any] = {}
remove_apps = False remove_apps = False
if entry.data[CONF_HOST] != import_config[CONF_HOST]: if entry.data[CONF_HOST] != import_config[CONF_HOST]:
@ -393,10 +393,10 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Ask user for PIN to complete pairing process. Ask user for PIN to complete pairing process.
""" """
errors: dict[str, str] = {} errors: dict[str, str] = {}
assert self._data
# Start pairing process if it hasn't already started # Start pairing process if it hasn't already started
if not self._ch_type and not self._pairing_token: if not self._ch_type and not self._pairing_token:
assert self._data
dev = VizioAsync( dev = VizioAsync(
DEVICE_ID, DEVICE_ID,
self._data[CONF_HOST], self._data[CONF_HOST],

View File

@ -4,7 +4,7 @@ from __future__ import annotations
from datetime import timedelta from datetime import timedelta
import logging import logging
from pyvizio import VizioAsync from pyvizio import AppConfig, VizioAsync
from pyvizio.api.apps import find_app_name from pyvizio.api.apps import find_app_name
from pyvizio.const import APP_HOME, INPUT_APPS, NO_APP_RUNNING, UNKNOWN_APP from pyvizio.const import APP_HOME, INPUT_APPS, NO_APP_RUNNING, UNKNOWN_APP
@ -144,9 +144,8 @@ class VizioDevice(MediaPlayerEntity):
self._apps_coordinator = apps_coordinator self._apps_coordinator = apps_coordinator
self._volume_step = config_entry.options[CONF_VOLUME_STEP] self._volume_step = config_entry.options[CONF_VOLUME_STEP]
self._current_input = None self._current_input: str | None = None
self._current_app_config = None self._current_app_config: AppConfig | None = None
self._attr_app_name = None
self._available_inputs: list[str] = [] self._available_inputs: list[str] = []
self._available_apps: list[str] = [] self._available_apps: list[str] = []
self._all_apps = apps_coordinator.data if apps_coordinator else None self._all_apps = apps_coordinator.data if apps_coordinator else None
@ -377,7 +376,7 @@ class VizioDevice(MediaPlayerEntity):
return self._available_inputs return self._available_inputs
@property @property
def app_id(self) -> str | None: def app_id(self):
"""Return the ID of the current app if it is unknown by pyvizio.""" """Return the ID of the current app if it is unknown by pyvizio."""
if self._current_app_config and self.source == UNKNOWN_APP: if self._current_app_config and self.source == UNKNOWN_APP:
return { return {
@ -388,9 +387,9 @@ class VizioDevice(MediaPlayerEntity):
return None return None
async def async_select_sound_mode(self, sound_mode): async def async_select_sound_mode(self, sound_mode: str) -> None:
"""Select sound mode.""" """Select sound mode."""
if sound_mode in self._attr_sound_mode_list: if sound_mode in (self._attr_sound_mode_list or ()):
await self._device.set_setting( await self._device.set_setting(
VIZIO_AUDIO_SETTINGS, VIZIO_AUDIO_SETTINGS,
VIZIO_SOUND_MODE, VIZIO_SOUND_MODE,