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]
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)
await coordinator.async_config_entry_first_refresh()
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]]]):
"""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."""
super().__init__(
hass,

View file

@ -188,8 +188,8 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
"""Initialize config flow."""
self._user_schema = None
self._must_show_form: bool | None = None
self._ch_type = None
self._pairing_token = None
self._ch_type: str | None = None
self._pairing_token: str | None = None
self._data: dict[str, Any] | None = None
self._apps: dict[str, list] = {}
@ -208,7 +208,7 @@ class VizioConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
self, user_input: dict[str, Any] | None = None
) -> FlowResult:
"""Handle a flow initialized by the user."""
errors = {}
errors: dict[str, str] = {}
if user_input is not None:
# 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(
_host_is_same, entry.data[CONF_HOST], import_config[CONF_HOST]
):
updated_options = {}
updated_data = {}
updated_options: dict[str, Any] = {}
updated_data: dict[str, Any] = {}
remove_apps = False
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.
"""
errors: dict[str, str] = {}
assert self._data
# Start pairing process if it hasn't already started
if not self._ch_type and not self._pairing_token:
assert self._data
dev = VizioAsync(
DEVICE_ID,
self._data[CONF_HOST],

View file

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