Add type annotations to some hassio API (#83103)

* Add type annotations to some hassio API

* Adjust callers
This commit is contained in:
Erik Montnemery 2022-12-02 11:18:49 +01:00 committed by GitHub
parent faea29a268
commit 4edebacba5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 15 deletions

View file

@ -144,7 +144,7 @@ class Analytics:
async def send_analytics(self, _=None) -> None: async def send_analytics(self, _=None) -> None:
"""Send analytics.""" """Send analytics."""
supervisor_info = None supervisor_info = None
operating_system_info = {} operating_system_info: dict[str, Any] = {}
if not self.onboarded or not self.preferences.get(ATTR_BASE, False): if not self.onboarded or not self.preferences.get(ATTR_BASE, False):
LOGGER.debug("Nothing to submit") LOGGER.debug("Nothing to submit")
@ -156,7 +156,7 @@ class Analytics:
if self.supervisor: if self.supervisor:
supervisor_info = hassio.get_supervisor_info(self.hass) 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) system_info = await async_get_system_info(self.hass)
integrations = [] integrations = []

View file

@ -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 # The hassio integration has not yet fetched data from the supervisor
raise ConfigEntryNotReady raise ConfigEntryNotReady
board: str board: str | None
if (board := os_info.get("board")) is None or not board.startswith("odroid"): 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 # Not running on a Hardkernel board, Home Assistant may have been migrated
hass.async_create_task(hass.config_entries.async_remove(entry.entry_id)) hass.async_create_task(hass.config_entries.async_remove(entry.entry_id))

View file

@ -21,7 +21,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]:
"""Return board info.""" """Return board info."""
if (os_info := get_os_info(hass)) is None: if (os_info := get_os_info(hass)) is None:
raise HomeAssistantError raise HomeAssistantError
board: str board: str | None
if (board := os_info.get("board")) is None: if (board := os_info.get("board")) is None:
raise HomeAssistantError raise HomeAssistantError
if not board.startswith("odroid"): if not board.startswith("odroid"):

View file

@ -241,7 +241,7 @@ HARDWARE_INTEGRATIONS = {
@callback @callback
@bind_hass @bind_hass
def get_info(hass): def get_info(hass: HomeAssistant) -> dict[str, Any] | None:
"""Return generic information from Supervisor. """Return generic information from Supervisor.
Async friendly. Async friendly.
@ -251,7 +251,7 @@ def get_info(hass):
@callback @callback
@bind_hass @bind_hass
def get_host_info(hass): def get_host_info(hass: HomeAssistant) -> dict[str, Any] | None:
"""Return generic host information. """Return generic host information.
Async friendly. Async friendly.
@ -261,7 +261,7 @@ def get_host_info(hass):
@callback @callback
@bind_hass @bind_hass
def get_store(hass): def get_store(hass: HomeAssistant) -> dict[str, Any] | None:
"""Return store information. """Return store information.
Async friendly. Async friendly.
@ -311,7 +311,7 @@ def get_addons_changelogs(hass):
@callback @callback
@bind_hass @bind_hass
def get_os_info(hass): def get_os_info(hass: HomeAssistant) -> dict[str, Any] | None:
"""Return OS information. """Return OS information.
Async friendly. Async friendly.
@ -321,7 +321,7 @@ def get_os_info(hass):
@callback @callback
@bind_hass @bind_hass
def get_core_info(hass): def get_core_info(hass: HomeAssistant) -> dict[str, Any] | None:
"""Return Home Assistant Core information from Supervisor. """Return Home Assistant Core information from Supervisor.
Async friendly. Async friendly.
@ -723,7 +723,7 @@ class HassioDataUpdateCoordinator(DataUpdateCoordinator):
addons_info = get_addons_info(self.hass) addons_info = get_addons_info(self.hass)
addons_stats = get_addons_stats(self.hass) addons_stats = get_addons_stats(self.hass)
addons_changelogs = get_addons_changelogs(self.hass) addons_changelogs = get_addons_changelogs(self.hass)
store_data = get_store(self.hass) store_data = get_store(self.hass) or {}
repositories = { repositories = {
repo[ATTR_SLUG]: repo[ATTR_NAME] repo[ATTR_SLUG]: repo[ATTR_NAME]

View file

@ -22,8 +22,8 @@ def async_register(
async def system_health_info(hass: HomeAssistant): async def system_health_info(hass: HomeAssistant):
"""Get info for the info page.""" """Get info for the info page."""
info = get_info(hass) info = get_info(hass) or {}
host_info = get_host_info(hass) host_info = get_host_info(hass) or {}
supervisor_info = get_supervisor_info(hass) supervisor_info = get_supervisor_info(hass)
healthy: bool | dict[str, str] healthy: bool | dict[str, str]
@ -57,7 +57,7 @@ async def system_health_info(hass: HomeAssistant):
} }
if info.get("hassos") is not None: 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["board"] = os_info.get("board")
information["supervisor_api"] = system_health.async_check_can_reach_url( information["supervisor_api"] = system_health.async_check_can_reach_url(

View file

@ -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 # The hassio integration has not yet fetched data from the supervisor
raise ConfigEntryNotReady raise ConfigEntryNotReady
board: str board: str | None
if (board := os_info.get("board")) is None or not board.startswith("rpi"): 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 # Not running on a Raspberry Pi, Home Assistant may have been migrated
hass.async_create_task(hass.config_entries.async_remove(entry.entry_id)) hass.async_create_task(hass.config_entries.async_remove(entry.entry_id))

View file

@ -36,7 +36,7 @@ def async_info(hass: HomeAssistant) -> list[HardwareInfo]:
"""Return board info.""" """Return board info."""
if (os_info := get_os_info(hass)) is None: if (os_info := get_os_info(hass)) is None:
raise HomeAssistantError raise HomeAssistantError
board: str board: str | None
if (board := os_info.get("board")) is None: if (board := os_info.get("board")) is None:
raise HomeAssistantError raise HomeAssistantError
if not board.startswith("rpi"): if not board.startswith("rpi"):