mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Add missing type annotations to Guardian (#52598)
This commit is contained in:
parent
e895b6cd42
commit
50d56fd755
@ -219,7 +219,7 @@ class GuardianEntity(CoordinatorEntity):
|
||||
self._entry = entry
|
||||
|
||||
@callback
|
||||
def _async_update_from_latest_data(self):
|
||||
def _async_update_from_latest_data(self) -> None:
|
||||
"""Update the entity.
|
||||
|
||||
This should be extended by Guardian platforms.
|
||||
@ -265,8 +265,8 @@ class ValveControllerEntity(GuardianEntity):
|
||||
coordinators: dict[str, DataUpdateCoordinator],
|
||||
kind: str,
|
||||
name: str,
|
||||
device_class: str,
|
||||
icon: str,
|
||||
device_class: str | None,
|
||||
icon: str | None,
|
||||
) -> None:
|
||||
"""Initialize."""
|
||||
super().__init__(entry, kind, name, device_class, icon)
|
||||
@ -292,7 +292,7 @@ class ValveControllerEntity(GuardianEntity):
|
||||
if coordinator
|
||||
)
|
||||
|
||||
async def _async_continue_entity_setup(self):
|
||||
async def _async_continue_entity_setup(self) -> None:
|
||||
"""Perform additional, internal tasks when the entity is about to be added.
|
||||
|
||||
This should be extended by Guardian platforms.
|
||||
|
@ -1,12 +1,18 @@
|
||||
"""Config flow for Elexa Guardian integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from aioguardian import Client
|
||||
from aioguardian.errors import GuardianError
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries, core
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.dhcp import IP_ADDRESS
|
||||
from homeassistant.const import CONF_IP_ADDRESS, CONF_PORT
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.data_entry_flow import FlowResult
|
||||
from homeassistant.helpers.typing import DiscoveryInfoType
|
||||
|
||||
from .const import CONF_UID, DOMAIN, LOGGER
|
||||
|
||||
@ -23,18 +29,18 @@ UNIQUE_ID = "guardian_{0}"
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_pin_from_discovery_hostname(hostname):
|
||||
def async_get_pin_from_discovery_hostname(hostname: str) -> str:
|
||||
"""Get the device's 4-digit PIN from its zeroconf-discovered hostname."""
|
||||
return hostname.split(".")[0].split("-")[1]
|
||||
|
||||
|
||||
@callback
|
||||
def async_get_pin_from_uid(uid):
|
||||
def async_get_pin_from_uid(uid: str) -> str:
|
||||
"""Get the device's 4-digit PIN from its UID."""
|
||||
return uid[-4:]
|
||||
|
||||
|
||||
async def validate_input(hass: core.HomeAssistant, data):
|
||||
async def validate_input(hass: HomeAssistant, data: dict[str, Any]):
|
||||
"""Validate the user input allows us to connect.
|
||||
|
||||
Data has the keys from DATA_SCHEMA with values provided by the user.
|
||||
@ -52,11 +58,11 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
VERSION = 1
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
"""Initialize."""
|
||||
self.discovery_info = {}
|
||||
|
||||
async def _async_set_unique_id(self, pin):
|
||||
async def _async_set_unique_id(self, pin: str) -> None:
|
||||
"""Set the config entry's unique ID (based on the device's 4-digit PIN)."""
|
||||
await self.async_set_unique_id(UNIQUE_ID.format(pin))
|
||||
if self.discovery_info:
|
||||
@ -66,7 +72,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
else:
|
||||
self._abort_if_unique_id_configured()
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Handle configuration via the UI."""
|
||||
if user_input is None:
|
||||
return self.async_show_form(
|
||||
@ -90,7 +98,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
title=info[CONF_UID], data={CONF_UID: info["uid"], **user_input}
|
||||
)
|
||||
|
||||
async def async_step_dhcp(self, discovery_info):
|
||||
async def async_step_dhcp(self, discovery_info: DiscoveryInfoType) -> FlowResult:
|
||||
"""Handle the configuration via dhcp."""
|
||||
self.discovery_info = {
|
||||
CONF_IP_ADDRESS: discovery_info[IP_ADDRESS],
|
||||
@ -98,7 +106,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
}
|
||||
return await self._async_handle_discovery()
|
||||
|
||||
async def async_step_zeroconf(self, discovery_info):
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: DiscoveryInfoType
|
||||
) -> FlowResult:
|
||||
"""Handle the configuration via zeroconf."""
|
||||
self.discovery_info = {
|
||||
CONF_IP_ADDRESS: discovery_info["host"],
|
||||
@ -108,7 +118,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
await self._async_set_unique_id(pin)
|
||||
return await self._async_handle_discovery()
|
||||
|
||||
async def _async_handle_discovery(self):
|
||||
async def _async_handle_discovery(self) -> FlowResult:
|
||||
"""Handle any discovery."""
|
||||
self.context[CONF_IP_ADDRESS] = self.discovery_info[CONF_IP_ADDRESS]
|
||||
if any(
|
||||
@ -119,7 +129,9 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
return await self.async_step_discovery_confirm()
|
||||
|
||||
async def async_step_discovery_confirm(self, user_input=None):
|
||||
async def async_step_discovery_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
"""Finish the configuration via any discovery."""
|
||||
if user_input is None:
|
||||
self._set_confirm_only()
|
||||
|
Loading…
x
Reference in New Issue
Block a user