-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path__init__.py
More file actions
49 lines (33 loc) · 1.62 KB
/
__init__.py
File metadata and controls
49 lines (33 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""Roborock Custom Map integration."""
from __future__ import annotations
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant, callback
from homeassistant.exceptions import ConfigEntryNotReady
from .const import CONF_MAP_ROTATION, DOMAIN
PLATFORMS = [Platform.IMAGE, Platform.SELECT]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Roborock Custom map from a config entry."""
roborock_entries = hass.config_entries.async_entries("roborock")
coordinators = []
@callback
def unload_this_entry() -> None:
hass.async_create_task(hass.config_entries.async_reload(entry.entry_id))
for r_entry in roborock_entries:
if r_entry.state == ConfigEntryState.LOADED:
coordinators.extend(r_entry.runtime_data.v1)
r_entry.async_on_unload(unload_this_entry)
if not coordinators:
raise ConfigEntryNotReady("No Roborock entries loaded. Cannot start.")
entry.runtime_data = coordinators
hass.data.setdefault(DOMAIN, {})
hass.data[DOMAIN].setdefault(entry.entry_id, {})
hass.data[DOMAIN][entry.entry_id].setdefault(CONF_MAP_ROTATION, {})
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
return True
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unloaded = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unloaded:
hass.data.get(DOMAIN, {}).pop(entry.entry_id, None)
return unloaded