mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 11:47:06 +00:00
Store awair flow data in flow handler attributes (#127381)
This commit is contained in:
parent
0fde5c21b7
commit
be3a883c51
@ -3,7 +3,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Mapping
|
from collections.abc import Mapping
|
||||||
from typing import Any
|
from typing import Any, Self, cast
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientError
|
from aiohttp.client_exceptions import ClientError
|
||||||
from python_awair import Awair, AwairLocal, AwairLocalDevice
|
from python_awair import Awair, AwairLocal, AwairLocalDevice
|
||||||
@ -26,16 +26,17 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
_device: AwairLocalDevice
|
_device: AwairLocalDevice
|
||||||
|
host: str
|
||||||
|
|
||||||
async def async_step_zeroconf(
|
async def async_step_zeroconf(
|
||||||
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
self, discovery_info: zeroconf.ZeroconfServiceInfo
|
||||||
) -> ConfigFlowResult:
|
) -> ConfigFlowResult:
|
||||||
"""Handle zeroconf discovery."""
|
"""Handle zeroconf discovery."""
|
||||||
|
|
||||||
host = discovery_info.host
|
self.host = discovery_info.host
|
||||||
LOGGER.debug("Discovered device: %s", host)
|
LOGGER.debug("Discovered device: %s", self.host)
|
||||||
|
|
||||||
self._device, _ = await self._check_local_connection(host)
|
self._device, _ = await self._check_local_connection(self.host)
|
||||||
|
|
||||||
if self._device is not None:
|
if self._device is not None:
|
||||||
await self.async_set_unique_id(self._device.mac_address)
|
await self.async_set_unique_id(self._device.mac_address)
|
||||||
@ -45,7 +46,6 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
)
|
)
|
||||||
self.context.update(
|
self.context.update(
|
||||||
{
|
{
|
||||||
"host": host,
|
|
||||||
"title_placeholders": {
|
"title_placeholders": {
|
||||||
"model": self._device.model,
|
"model": self._device.model,
|
||||||
"device_id": self._device.device_id,
|
"device_id": self._device.device_id,
|
||||||
@ -119,12 +119,16 @@ class AwairFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
def _get_discovered_entries(self) -> dict[str, str]:
|
def _get_discovered_entries(self) -> dict[str, str]:
|
||||||
"""Get discovered entries."""
|
"""Get discovered entries."""
|
||||||
entries: dict[str, str] = {}
|
entries: dict[str, str] = {}
|
||||||
for flow in self._async_in_progress():
|
|
||||||
if flow["context"]["source"] == SOURCE_ZEROCONF:
|
flows = cast(
|
||||||
info = flow["context"]["title_placeholders"]
|
set[Self],
|
||||||
entries[flow["context"]["host"]] = (
|
self.hass.config_entries.flow._handler_progress_index.get(DOMAIN) or set(), # noqa: SLF001
|
||||||
f"{info['model']} ({info['device_id']})"
|
|
||||||
)
|
)
|
||||||
|
for flow in flows:
|
||||||
|
if flow.source != SOURCE_ZEROCONF:
|
||||||
|
continue
|
||||||
|
info = flow.context["title_placeholders"]
|
||||||
|
entries[flow.host] = f"{info['model']} ({info['device_id']})"
|
||||||
return entries
|
return entries
|
||||||
|
|
||||||
async def async_step_local(
|
async def async_step_local(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user