mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Improve config flow type hints in screenlogic (#125199)
This commit is contained in:
parent
349ea35dc3
commit
416a2de179
@ -32,9 +32,9 @@ GATEWAY_MANUAL_ENTRY = "manual"
|
|||||||
PENTAIR_OUI = "00-C0-33"
|
PENTAIR_OUI = "00-C0-33"
|
||||||
|
|
||||||
|
|
||||||
async def async_discover_gateways_by_unique_id(hass):
|
async def async_discover_gateways_by_unique_id() -> dict[str, dict[str, Any]]:
|
||||||
"""Discover gateways and return a dict of them by unique id."""
|
"""Discover gateways and return a dict of them by unique id."""
|
||||||
discovered_gateways = {}
|
discovered_gateways: dict[str, dict[str, Any]] = {}
|
||||||
try:
|
try:
|
||||||
hosts = await discovery.async_discover()
|
hosts = await discovery.async_discover()
|
||||||
_LOGGER.debug("Discovered hosts: %s", hosts)
|
_LOGGER.debug("Discovered hosts: %s", hosts)
|
||||||
@ -51,16 +51,16 @@ async def async_discover_gateways_by_unique_id(hass):
|
|||||||
return discovered_gateways
|
return discovered_gateways
|
||||||
|
|
||||||
|
|
||||||
def _extract_mac_from_name(name):
|
def _extract_mac_from_name(name: str) -> str:
|
||||||
return format_mac(f"{PENTAIR_OUI}-{name.split(':')[1].strip()}")
|
return format_mac(f"{PENTAIR_OUI}-{name.split(':')[1].strip()}")
|
||||||
|
|
||||||
|
|
||||||
def short_mac(mac):
|
def short_mac(mac: str) -> str:
|
||||||
"""Short version of the mac as seen in the app."""
|
"""Short version of the mac as seen in the app."""
|
||||||
return "-".join(mac.split(":")[3:]).upper()
|
return "-".join(mac.split(":")[3:]).upper()
|
||||||
|
|
||||||
|
|
||||||
def name_for_mac(mac):
|
def name_for_mac(mac: str) -> str:
|
||||||
"""Derive the gateway name from the mac."""
|
"""Derive the gateway name from the mac."""
|
||||||
return f"Pentair: {short_mac(mac)}"
|
return f"Pentair: {short_mac(mac)}"
|
||||||
|
|
||||||
@ -83,9 +83,11 @@ class ScreenlogicConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
"""Get the options flow for ScreenLogic."""
|
"""Get the options flow for ScreenLogic."""
|
||||||
return ScreenLogicOptionsFlowHandler(config_entry)
|
return ScreenLogicOptionsFlowHandler(config_entry)
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None) -> ConfigFlowResult:
|
async def async_step_user(
|
||||||
|
self, user_input: dict[str, Any] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Handle the start of the config flow."""
|
"""Handle the start of the config flow."""
|
||||||
self.discovered_gateways = await async_discover_gateways_by_unique_id(self.hass)
|
self.discovered_gateways = await async_discover_gateways_by_unique_id()
|
||||||
return await self.async_step_gateway_select()
|
return await self.async_step_gateway_select()
|
||||||
|
|
||||||
async def async_step_dhcp(
|
async def async_step_dhcp(
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from screenlogicpy import ScreenLogicGateway
|
from screenlogicpy import ScreenLogicGateway
|
||||||
from screenlogicpy.const.common import (
|
from screenlogicpy.const.common import (
|
||||||
@ -33,11 +34,13 @@ async def async_get_connect_info(
|
|||||||
"""Construct connect_info from configuration entry and returns it to caller."""
|
"""Construct connect_info from configuration entry and returns it to caller."""
|
||||||
mac = entry.unique_id
|
mac = entry.unique_id
|
||||||
# Attempt to rediscover gateway to follow IP changes
|
# Attempt to rediscover gateway to follow IP changes
|
||||||
discovered_gateways = await async_discover_gateways_by_unique_id(hass)
|
discovered_gateways = await async_discover_gateways_by_unique_id()
|
||||||
if mac in discovered_gateways:
|
if mac in discovered_gateways:
|
||||||
return discovered_gateways[mac]
|
return discovered_gateways[mac]
|
||||||
|
|
||||||
_LOGGER.debug("Gateway rediscovery failed for %s", entry.title)
|
_LOGGER.debug("Gateway rediscovery failed for %s", entry.title)
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert mac is not None
|
||||||
# Static connection defined or fallback from discovery
|
# Static connection defined or fallback from discovery
|
||||||
return {
|
return {
|
||||||
SL_GATEWAY_NAME: name_for_mac(mac),
|
SL_GATEWAY_NAME: name_for_mac(mac),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user