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:
"""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 = []

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
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))

View file

@ -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"):

View file

@ -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]

View file

@ -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(

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
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))

View file

@ -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"):