mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Improve config flow type hints in ukraine_alarm (#125302)
This commit is contained in:
parent
a8f2204f4f
commit
f778033bd8
@ -3,7 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from uasiren.client import Client
|
from uasiren.client import Client
|
||||||
@ -25,7 +25,7 @@ class UkraineAlarmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Initialize a new UkraineAlarmConfigFlow."""
|
"""Initialize a new UkraineAlarmConfigFlow."""
|
||||||
self.states = None
|
self.states: list[dict[str, Any]] | None = None
|
||||||
self.selected_region: dict[str, Any] | None = None
|
self.selected_region: dict[str, Any] | None = None
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
@ -69,17 +69,25 @@ class UkraineAlarmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
return await self._handle_pick_region("user", "district", user_input)
|
return await self._handle_pick_region("user", "district", user_input)
|
||||||
|
|
||||||
async def async_step_district(self, user_input=None):
|
async def async_step_district(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Handle user-chosen district."""
|
"""Handle user-chosen district."""
|
||||||
return await self._handle_pick_region("district", "community", user_input)
|
return await self._handle_pick_region("district", "community", user_input)
|
||||||
|
|
||||||
async def async_step_community(self, user_input=None):
|
async def async_step_community(
|
||||||
|
self, user_input: dict[str, str] | None = None
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Handle user-chosen community."""
|
"""Handle user-chosen community."""
|
||||||
return await self._handle_pick_region("community", None, user_input, True)
|
return await self._handle_pick_region("community", None, user_input, True)
|
||||||
|
|
||||||
async def _handle_pick_region(
|
async def _handle_pick_region(
|
||||||
self, step_id: str, next_step: str | None, user_input, last_step=False
|
self,
|
||||||
):
|
step_id: str,
|
||||||
|
next_step: str | None,
|
||||||
|
user_input: dict[str, str] | None,
|
||||||
|
last_step: bool = False,
|
||||||
|
) -> ConfigFlowResult:
|
||||||
"""Handle picking a (sub)region."""
|
"""Handle picking a (sub)region."""
|
||||||
if self.selected_region:
|
if self.selected_region:
|
||||||
source = self.selected_region["regionChildIds"]
|
source = self.selected_region["regionChildIds"]
|
||||||
@ -121,8 +129,10 @@ class UkraineAlarmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
step_id=step_id, data_schema=schema, last_step=last_step
|
step_id=step_id, data_schema=schema, last_step=last_step
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_finish_flow(self):
|
async def _async_finish_flow(self) -> ConfigFlowResult:
|
||||||
"""Finish the setup."""
|
"""Finish the setup."""
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
assert self.selected_region is not None
|
||||||
await self.async_set_unique_id(self.selected_region["regionId"])
|
await self.async_set_unique_id(self.selected_region["regionId"])
|
||||||
self._abort_if_unique_id_configured()
|
self._abort_if_unique_id_configured()
|
||||||
|
|
||||||
@ -135,10 +145,10 @@ class UkraineAlarmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _find(regions, region_id):
|
def _find(regions: list[dict[str, Any]], region_id):
|
||||||
return next((region for region in regions if region["regionId"] == region_id), None)
|
return next((region for region in regions if region["regionId"] == region_id), None)
|
||||||
|
|
||||||
|
|
||||||
def _make_regions_object(regions):
|
def _make_regions_object(regions: list[dict[str, Any]]) -> dict[str, str]:
|
||||||
regions = sorted(regions, key=lambda region: region["regionName"].lower())
|
regions = sorted(regions, key=lambda region: region["regionName"].lower())
|
||||||
return {region["regionId"]: region["regionName"] for region in regions}
|
return {region["regionId"]: region["regionName"] for region in regions}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user