2019-03-17 03:44:05 +00:00
|
|
|
"""The gogogate2 component."""
|
2021-03-02 03:34:37 +00:00
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-04 12:26:40 +00:00
|
|
|
from homeassistant.const import CONF_DEVICE, Platform
|
2020-05-16 15:53:11 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
|
|
|
|
from .common import get_data_update_coordinator
|
2020-09-05 14:26:01 +00:00
|
|
|
from .const import DEVICE_TYPE_GOGOGATE2
|
2020-05-16 15:53:11 +00:00
|
|
|
|
2021-12-04 12:26:40 +00:00
|
|
|
PLATFORMS = [Platform.COVER, Platform.SENSOR]
|
2021-03-02 03:34:37 +00:00
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
|
2021-04-27 14:09:59 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-05-16 15:53:11 +00:00
|
|
|
"""Do setup of Gogogate2."""
|
2020-09-05 14:26:01 +00:00
|
|
|
|
|
|
|
# Update the config entry.
|
|
|
|
config_updates = {}
|
2021-04-27 14:09:59 +00:00
|
|
|
if CONF_DEVICE not in entry.data:
|
2021-07-03 15:06:42 +00:00
|
|
|
config_updates = {
|
2021-04-27 14:09:59 +00:00
|
|
|
**entry.data,
|
2020-09-05 14:26:01 +00:00
|
|
|
**{CONF_DEVICE: DEVICE_TYPE_GOGOGATE2},
|
|
|
|
}
|
|
|
|
|
|
|
|
if config_updates:
|
2021-07-03 15:06:42 +00:00
|
|
|
hass.config_entries.async_update_entry(entry, data=config_updates)
|
2020-09-05 14:26:01 +00:00
|
|
|
|
2021-04-27 14:09:59 +00:00
|
|
|
data_update_coordinator = get_data_update_coordinator(hass, entry)
|
2021-03-29 22:51:39 +00:00
|
|
|
await data_update_coordinator.async_config_entry_first_refresh()
|
2020-05-16 15:53:11 +00:00
|
|
|
|
2021-04-27 14:09:59 +00:00
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
2020-05-16 15:53:11 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2021-04-27 14:09:59 +00:00
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
2020-05-16 15:53:11 +00:00
|
|
|
"""Unload Gogogate2 config entry."""
|
2021-04-27 14:09:59 +00:00
|
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|