2020-09-24 14:39:24 +00:00
|
|
|
"""The 1-Wire component."""
|
2021-04-01 13:06:47 +00:00
|
|
|
import logging
|
2020-10-24 01:57:16 +00:00
|
|
|
|
2020-10-26 15:33:13 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-04-22 18:23:19 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2020-10-26 15:33:13 +00:00
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
|
2021-03-02 20:43:59 +00:00
|
|
|
from .const import DOMAIN, PLATFORMS
|
2020-10-26 15:33:13 +00:00
|
|
|
from .onewirehub import CannotConnect, OneWireHub
|
2020-10-24 01:57:16 +00:00
|
|
|
|
2021-04-01 13:06:47 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2020-10-24 01:57:16 +00:00
|
|
|
|
2021-05-27 13:56:20 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-10-24 01:57:16 +00:00
|
|
|
"""Set up a 1-Wire proxy for a config entry."""
|
2020-10-26 15:33:13 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
|
|
|
|
onewirehub = OneWireHub(hass)
|
|
|
|
try:
|
2021-05-27 13:56:20 +00:00
|
|
|
await onewirehub.initialize(entry)
|
2020-10-26 15:33:13 +00:00
|
|
|
except CannotConnect as exc:
|
|
|
|
raise ConfigEntryNotReady() from exc
|
|
|
|
|
2021-05-27 13:56:20 +00:00
|
|
|
hass.data[DOMAIN][entry.entry_id] = onewirehub
|
2020-10-26 15:33:13 +00:00
|
|
|
|
2021-12-01 17:38:07 +00:00
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
2021-04-01 13:06:47 +00:00
|
|
|
|
2020-10-24 01:57:16 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-05-11 15:28:17 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
2020-10-24 01:57:16 +00:00
|
|
|
"""Unload a config entry."""
|
2021-04-27 18:42:21 +00:00
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
|
|
|
config_entry, PLATFORMS
|
2020-10-24 01:57:16 +00:00
|
|
|
)
|
2020-10-26 15:33:13 +00:00
|
|
|
if unload_ok:
|
2021-05-07 12:21:03 +00:00
|
|
|
hass.data[DOMAIN].pop(config_entry.entry_id)
|
2020-10-24 01:57:16 +00:00
|
|
|
return unload_ok
|