Repository navigation
Expand file tree
/
Copy path__init__.py
More file actions
46 lines (35 loc) · 1.49 KB
/
Copy path__init__.py
File metadata and controls
46 lines (35 loc) · 1.49 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
import asyncio
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
import logging
_LOGGER = logging.getLogger(__name__)
from .const import DOMAIN
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up SIB from a config entry."""
hass.data.setdefault(DOMAIN, {})
hass_
4F34
data = dict(entry.data)
# Registers update listener to update config entry when options are updated.
hass_data["unsub_options_update_listener"] = entry.add_update_listener(options_update_listener)
hass.data[DOMAIN][entry.entry_id] = hass_data
# Forward entry setup to the platforms
hass.async_create_task(
hass.config_entries.async_forward_entry_setups(entry, ["binary_sensor"])
)
return True
async def options_update_listener(hass: HomeAssistant, config_entry: ConfigEntry):
"""Handle options update."""
_LOGGER.warn("UPDATE LISTENER CALLED!")
await hass.config_entries.async_reload(config_entry.entry_id)
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = all(
await asyncio.gather(
*[hass.config_entries.async_forward_entry_unload(entry, "binary_sensor")]
)
)
# Remove options_update_listener.
hass.data[DOMAIN][entry.entry_id]["unsub_options_update_listener"]()
# Remove config entry from domain.
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
return unload_ok