|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import logging |
6 | | -from typing import Any |
7 | 6 |
|
| 7 | +# from typing import Any |
8 | 8 | from google_nest_sdm.device import Device |
9 | 9 |
|
10 | 10 | # pylint: disable=hass-component-root-import |
11 | 11 | from homeassistant.components.nest.climate import ThermostatHvacTrait |
12 | 12 | from homeassistant.components.nest.const import DOMAIN as NEST_DOMAIN |
13 | 13 | from homeassistant.components.nest.types import NestConfigEntry |
14 | 14 |
|
15 | | -# pylint: enable=hass-component-root-import |
16 | | -from homeassistant.config_entries import ConfigFlow, ConfigFlowResult |
| 15 | +# from homeassistant.config_entries import ConfigFlow, ConfigFlowResult |
| 16 | +from homeassistant.core import HomeAssistant |
| 17 | +from homeassistant.helpers import config_entry_flow |
17 | 18 |
|
18 | 19 | from .const import DOMAIN |
19 | 20 |
|
20 | 21 | _LOGGER = logging.getLogger(__name__) |
21 | 22 |
|
22 | 23 |
|
23 | | -class GoogleNestFanFlow(ConfigFlow, domain=DOMAIN): |
24 | | - """Google Nest Fan Flow.""" |
25 | | - |
26 | | - async def async_step_user( |
27 | | - self, user_input: dict[str, Any] | None = None |
28 | | - ) -> ConfigFlowResult: |
29 | | - """Add the integration.""" |
30 | | - error: str = "" |
31 | | - entries: list[NestConfigEntry] = self.hass.config_entries.async_loaded_entries( |
32 | | - NEST_DOMAIN |
| 24 | +def _async_has_configured_thermostats(hass: HomeAssistant) -> bool: |
| 25 | + entries: list[NestConfigEntry] = hass.config_entries.async_loaded_entries( |
| 26 | + NEST_DOMAIN |
| 27 | + ) |
| 28 | + if not entries: |
| 29 | + return False |
| 30 | + devices: list[Device] = [] |
| 31 | + for entry in entries: |
| 32 | + devices.extend( |
| 33 | + device |
| 34 | + for device in entry.runtime_data.device_manager.devices.values() |
| 35 | + if ThermostatHvacTrait.NAME in device.traits |
33 | 36 | ) |
34 | | - if not entries: |
35 | | - error = "nest_not_loaded" |
36 | | - else: |
37 | | - devices: list[Device] = [] |
38 | | - for entry in entries: |
39 | | - devices.extend( |
40 | | - device |
41 | | - for device in entry.runtime_data.device_manager.devices.values() |
42 | | - if ThermostatHvacTrait.NAME in device.traits |
43 | | - ) |
44 | | - if not devices: |
45 | | - error = "no_thermostats" |
46 | | - if not error: |
47 | | - return self.async_create_entry( |
48 | | - title="Google Nest Fan Customization", |
49 | | - description="Will create entries for all Nest fans", |
50 | | - data={}, |
51 | | - ) |
52 | | - return self.async_abort(reason=error) |
| 37 | + return len(devices) > 0 |
| 38 | + |
| 39 | + |
| 40 | +config_entry_flow.register_discovery_flow( |
| 41 | + DOMAIN, "Google Nest Fan", _async_has_configured_thermostats |
| 42 | +) |
| 43 | + |
| 44 | + |
| 45 | +# class GoogleNestFanFlow(ConfigFlow, domain=DOMAIN): |
| 46 | +# """Google Nest Fan Flow.""" |
| 47 | + |
| 48 | +# async def async_step_user( |
| 49 | +# self, user_input: dict[str, Any] | None = None |
| 50 | +# ) -> ConfigFlowResult: |
| 51 | +# """Add the integration.""" |
| 52 | +# error: str = "" |
| 53 | +# entries: list[NestConfigEntry] = self.hass.config_entries.async_loaded_entries( |
| 54 | +# NEST_DOMAIN |
| 55 | +# ) |
| 56 | +# if not entries: |
| 57 | +# error = "nest_not_loaded" |
| 58 | +# else: |
| 59 | +# devices: list[Device] = [] |
| 60 | +# for entry in entries: |
| 61 | +# devices.extend( |
| 62 | +# device |
| 63 | +# for device in entry.runtime_data.device_manager.devices.values() |
| 64 | +# if ThermostatHvacTrait.NAME in device.traits |
| 65 | +# ) |
| 66 | +# if not devices: |
| 67 | +# error = "no_thermostats" |
| 68 | +# if not error: |
| 69 | +# return self.async_create_entry( |
| 70 | +# title="Google Nest Fan Customization", |
| 71 | +# description="Will create entries for all Nest fans", |
| 72 | +# data={}, |
| 73 | +# ) |
| 74 | +# return self.async_abort(reason=error) |
0 commit comments