Skip to content

Commit dadeb53

Browse files
authored
Merge pull request #128 from c-st/fix-config-flow-updates
Improve config flow updates
2 parents f98ab36 + f3b6433 commit dadeb53

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

DEVELOP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
./scripts/develop
99
```
1010

11-
Open extension [in browser](http://localhost:8123/).
11+
Open extension [in browser](http://localhost:8123/) and set up a new user.
1212

1313
## Translations
1414

config/configuration.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ logger:
1010
custom_components.auto_areas: debug
1111

1212
# https://www.home-assistant.io/integrations/demo/
13-
light:
14-
- platform: demo
1513

16-
binary_sensor:
17-
- platform: demo
14+
demo:
1815

1916
sensor:
2017
- platform: random

custom_components/auto_areas/__init__.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
3030
"""Initialize immediately"""
3131
await async_init(hass, entry, auto_area)
3232
else:
33-
"""Schedule initialization when HA is started"""
33+
"""Schedule initialization when HA is started and initialized"""
34+
3435
# https://developers.home-assistant.io/docs/asyncio_working_with_async/#calling-async-functions-from-threads
3536

3637
@callback
@@ -39,10 +40,6 @@ def init(hass: HomeAssistant, entry: ConfigEntry, auto_area: AutoArea):
3940
async_init(hass, entry, auto_area), hass.loop
4041
).result()
4142

42-
LOGGER.info(
43-
"😴 Deferring AutoAreas setup by 10 seconds to make sure all entities are ready")
44-
await asyncio.sleep(10)
45-
4643
hass.bus.async_listen_once(
4744
EVENT_HOMEASSISTANT_STARTED,
4845
lambda params: init(hass, entry, auto_area)
@@ -51,20 +48,22 @@ def init(hass: HomeAssistant, entry: ConfigEntry, auto_area: AutoArea):
5148
return True
5249

5350

54-
def initialize(hass: HomeAssistant, entry: ConfigEntry, auto_area: AutoArea):
55-
"""Initialize area after HA has started."""
56-
asyncio.run_coroutine_threadsafe(
57-
async_init(hass, entry, auto_area), hass.loop
58-
).result()
59-
60-
6151
async def async_init(hass: HomeAssistant, entry: ConfigEntry, auto_area: AutoArea):
6252
"""Initialize component."""
63-
await auto_area.initialize()
53+
await asyncio.sleep(5) # wait for all area devices to be initialized
54+
await auto_area.async_initialize()
55+
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
56+
6457
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
65-
hass.async_create_task(
66-
hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
67-
)
58+
59+
return True
60+
61+
62+
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
63+
"""Reload config entry."""
64+
LOGGER.info("🔄 Reloading entry %s", entry)
65+
66+
await hass.config_entries.async_reload(entry.entry_id)
6867

6968

7069
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
@@ -83,12 +82,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
8382
return unloaded
8483

8584

86-
async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
87-
"""Reload config entry."""
88-
await async_unload_entry(hass, entry)
89-
await async_setup_entry(hass, entry)
90-
91-
9285
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
9386
"""Check for YAML-config."""
9487

custom_components/auto_areas/auto_area.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
4141
self.area: AreaEntry = self.area_registry.async_get_area(self.area_id)
4242
self.auto_lights = None
4343

44-
async def initialize(self):
44+
async def async_initialize(self):
4545
"""Subscribe to area changes and reload if necessary."""
4646
LOGGER.info("%s: Initializing after HA start", self.area.name)
4747

custom_components/auto_areas/manifest.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
"button",
77
"group",
88
"binary_sensor",
9-
"sensor"
9+
"sensor",
10+
"mqtt"
1011
],
1112
"codeowners": [
1213
"@c-st"
1314
],
1415
"config_flow": true,
15-
"dependencies": [],
16+
"dependencies": [
17+
"light",
18+
"button",
19+
"group",
20+
"binary_sensor",
21+
"sensor"
22+
],
1623
"documentation": "https://github.com/c-st/auto_areas",
1724
"iot_class": "local_push",
1825
"issue_tracker": "https://github.com/c-st/auto_areas/issues",

0 commit comments

Comments
 (0)