2019-02-13 20:21:14 +00:00
|
|
|
"""Support for EnOcean devices."""
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2016-08-25 04:35:09 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
from homeassistant import config_entries, core
|
|
|
|
from homeassistant.config_entries import SOURCE_IMPORT
|
2016-08-25 04:35:09 +00:00
|
|
|
from homeassistant.const import CONF_DEVICE
|
|
|
|
import homeassistant.helpers.config_validation as cv
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
from .const import DATA_ENOCEAN, DOMAIN, ENOCEAN_DONGLE
|
|
|
|
from .dongle import EnOceanDongle
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
CONFIG_SCHEMA = vol.Schema(
|
|
|
|
{DOMAIN: vol.Schema({vol.Required(CONF_DEVICE): cv.string})}, extra=vol.ALLOW_EXTRA
|
|
|
|
)
|
2016-08-25 04:35:09 +00:00
|
|
|
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
async def async_setup(hass, config):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the EnOcean component."""
|
2020-07-09 00:46:38 +00:00
|
|
|
# support for text-based configuration (legacy)
|
|
|
|
if DOMAIN not in config:
|
|
|
|
return True
|
|
|
|
|
|
|
|
if hass.config_entries.async_entries(DOMAIN):
|
|
|
|
# We can only have one dongle. If there is already one in the config,
|
|
|
|
# there is no need to import the yaml based config.
|
|
|
|
return True
|
|
|
|
|
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.flow.async_init(
|
|
|
|
DOMAIN, context={"source": SOURCE_IMPORT}, data=config[DOMAIN]
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2020-07-09 00:46:38 +00:00
|
|
|
)
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
return True
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2019-04-24 22:30:46 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry
|
|
|
|
):
|
|
|
|
"""Set up an EnOcean dongle for the given entry."""
|
|
|
|
enocean_data = hass.data.setdefault(DATA_ENOCEAN, {})
|
|
|
|
usb_dongle = EnOceanDongle(hass, config_entry.data[CONF_DEVICE])
|
|
|
|
await usb_dongle.async_setup()
|
|
|
|
enocean_data[ENOCEAN_DONGLE] = usb_dongle
|
2019-04-24 22:30:46 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
return True
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2019-04-24 22:30:46 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
async def async_unload_entry(hass, config_entry):
|
|
|
|
"""Unload ENOcean config entry."""
|
2016-05-29 21:28:03 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
enocean_dongle = hass.data[DATA_ENOCEAN][ENOCEAN_DONGLE]
|
|
|
|
enocean_dongle.unload()
|
|
|
|
hass.data.pop(DATA_ENOCEAN)
|
2019-07-31 19:25:30 +00:00
|
|
|
|
2020-07-09 00:46:38 +00:00
|
|
|
return True
|