From 4edebacba5585227d5430a4c9191b4cdd2f4848c Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 2 Dec 2022 11:18:49 +0100 Subject: [PATCH] Add type annotations to some hassio API (#83103) * Add type annotations to some hassio API * Adjust callers --- homeassistant/components/analytics/analytics.py | 4 ++-- homeassistant/components/hardkernel/__init__.py | 2 +- homeassistant/components/hardkernel/hardware.py | 2 +- homeassistant/components/hassio/__init__.py | 12 ++++++------ homeassistant/components/hassio/system_health.py | 6 +++--- homeassistant/components/raspberry_pi/__init__.py | 2 +- homeassistant/components/raspberry_pi/hardware.py | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/analytics/analytics.py b/homeassistant/components/analytics/analytics.py index 2e53d9c03d5..f250d53c752 100644 --- a/homeassistant/components/analytics/analytics.py +++ b/homeassistant/components/analytics/analytics.py @@ -144,7 +144,7 @@ class Analytics: async def send_analytics(self, _=None) -> None: """Send analytics.""" supervisor_info = None - operating_system_info = {} + operating_system_info: dict[str, Any] = {} if not self.onboarded or not self.preferences.get(ATTR_BASE, False): LOGGER.debug("Nothing to submit") @@ -156,7 +156,7 @@ class Analytics: if self.supervisor: supervisor_info = hassio.get_supervisor_info(self.hass) - operating_system_info = hassio.get_os_info(self.hass) + operating_system_info = hassio.get_os_info(self.hass) or {} system_info = await async_get_system_info(self.hass) integrations = [] diff --git a/homeassistant/components/hardkernel/__init__.py b/homeassistant/components/hardkernel/__init__.py index 6dfe30b9e75..c81ad7860be 100644 --- a/homeassistant/components/hardkernel/__init__.py +++ b/homeassistant/components/hardkernel/__init__.py @@ -13,7 +13,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # The hassio integration has not yet fetched data from the supervisor raise ConfigEntryNotReady - board: str + board: str | None if (board := os_info.get("board")) is None or not board.startswith("odroid"): # Not running on a Hardkernel board, Home Assistant may have been migrated hass.async_create_task(hass.config_entries.async_remove(entry.entry_id)) diff --git a/homeassistant/components/hardkernel/hardware.py b/homeassistant/components/hardkernel/hardware.py index eca599960f8..cd83f684eac 100644 --- a/homeassistant/components/hardkernel/hardware.py +++ b/homeassistant/components/hardkernel/hardware.py @@ -21,7 +21,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: """Return board info.""" if (os_info := get_os_info(hass)) is None: raise HomeAssistantError - board: str + board: str | None if (board := os_info.get("board")) is None: raise HomeAssistantError if not board.startswith("odroid"): diff --git a/homeassistant/components/hassio/__init__.py b/homeassistant/components/hassio/__init__.py index 581ed0e3292..0d159915013 100644 --- a/homeassistant/components/hassio/__init__.py +++ b/homeassistant/components/hassio/__init__.py @@ -241,7 +241,7 @@ HARDWARE_INTEGRATIONS = { @callback @bind_hass -def get_info(hass): +def get_info(hass: HomeAssistant) -> dict[str, Any] | None: """Return generic information from Supervisor. Async friendly. @@ -251,7 +251,7 @@ def get_info(hass): @callback @bind_hass -def get_host_info(hass): +def get_host_info(hass: HomeAssistant) -> dict[str, Any] | None: """Return generic host information. Async friendly. @@ -261,7 +261,7 @@ def get_host_info(hass): @callback @bind_hass -def get_store(hass): +def get_store(hass: HomeAssistant) -> dict[str, Any] | None: """Return store information. Async friendly. @@ -311,7 +311,7 @@ def get_addons_changelogs(hass): @callback @bind_hass -def get_os_info(hass): +def get_os_info(hass: HomeAssistant) -> dict[str, Any] | None: """Return OS information. Async friendly. @@ -321,7 +321,7 @@ def get_os_info(hass): @callback @bind_hass -def get_core_info(hass): +def get_core_info(hass: HomeAssistant) -> dict[str, Any] | None: """Return Home Assistant Core information from Supervisor. Async friendly. @@ -723,7 +723,7 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator): addons_info = get_addons_info(self.hass) addons_stats = get_addons_stats(self.hass) addons_changelogs = get_addons_changelogs(self.hass) - store_data = get_store(self.hass) + store_data = get_store(self.hass) or {} repositories = { repo[ATTR_SLUG]: repo[ATTR_NAME] diff --git a/homeassistant/components/hassio/system_health.py b/homeassistant/components/hassio/system_health.py index 795d1e325fb..74437186ff2 100644 --- a/homeassistant/components/hassio/system_health.py +++ b/homeassistant/components/hassio/system_health.py @@ -22,8 +22,8 @@ def async_register( async def system_health_info(hass: HomeAssistant): """Get info for the info page.""" - info = get_info(hass) - host_info = get_host_info(hass) + info = get_info(hass) or {} + host_info = get_host_info(hass) or {} supervisor_info = get_supervisor_info(hass) healthy: bool | dict[str, str] @@ -57,7 +57,7 @@ async def system_health_info(hass: HomeAssistant): } if info.get("hassos") is not None: - os_info = get_os_info(hass) + os_info = get_os_info(hass) or {} information["board"] = os_info.get("board") information["supervisor_api"] = system_health.async_check_can_reach_url( diff --git a/homeassistant/components/raspberry_pi/__init__.py b/homeassistant/components/raspberry_pi/__init__.py index ab1114722c6..3750a1c7068 100644 --- a/homeassistant/components/raspberry_pi/__init__.py +++ b/homeassistant/components/raspberry_pi/__init__.py @@ -13,7 +13,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # The hassio integration has not yet fetched data from the supervisor raise ConfigEntryNotReady - board: str + board: str | None if (board := os_info.get("board")) is None or not board.startswith("rpi"): # Not running on a Raspberry Pi, Home Assistant may have been migrated hass.async_create_task(hass.config_entries.async_remove(entry.entry_id)) diff --git a/homeassistant/components/raspberry_pi/hardware.py b/homeassistant/components/raspberry_pi/hardware.py index 61417f751ac..e90316ccb3c 100644 --- a/homeassistant/components/raspberry_pi/hardware.py +++ b/homeassistant/components/raspberry_pi/hardware.py @@ -36,7 +36,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]: """Return board info.""" if (os_info := get_os_info(hass)) is None: raise HomeAssistantError - board: str + board: str | None if (board := os_info.get("board")) is None: raise HomeAssistantError if not board.startswith("rpi"):