2019-03-17 03:44:05 +00:00
|
|
|
"""The gogogate2 component."""
|
2021-03-02 03:34:37 +00:00
|
|
|
import asyncio
|
|
|
|
|
|
|
|
from homeassistant.components.cover import DOMAIN as COVER
|
|
|
|
from homeassistant.components.sensor import DOMAIN as SENSOR
|
2020-05-16 15:53:11 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2020-09-05 14:26:01 +00:00
|
|
|
from homeassistant.const import CONF_DEVICE
|
2020-05-16 15:53:11 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.exceptions import ConfigEntryNotReady
|
|
|
|
|
|
|
|
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-03-02 03:34:37 +00:00
|
|
|
PLATFORMS = [COVER, SENSOR]
|
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
|
|
|
|
async def async_setup(hass: HomeAssistant, base_config: dict) -> bool:
|
|
|
|
"""Set up for Gogogate2 controllers."""
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
|
|
|
"""Do setup of Gogogate2."""
|
2020-09-05 14:26:01 +00:00
|
|
|
|
|
|
|
# Update the config entry.
|
|
|
|
config_updates = {}
|
|
|
|
if CONF_DEVICE not in config_entry.data:
|
|
|
|
config_updates["data"] = {
|
|
|
|
**config_entry.data,
|
|
|
|
**{CONF_DEVICE: DEVICE_TYPE_GOGOGATE2},
|
|
|
|
}
|
|
|
|
|
|
|
|
if config_updates:
|
|
|
|
hass.config_entries.async_update_entry(config_entry, **config_updates)
|
|
|
|
|
2020-05-16 15:53:11 +00:00
|
|
|
data_update_coordinator = get_data_update_coordinator(hass, config_entry)
|
|
|
|
await data_update_coordinator.async_refresh()
|
|
|
|
|
|
|
|
if not data_update_coordinator.last_update_success:
|
|
|
|
raise ConfigEntryNotReady()
|
|
|
|
|
2021-03-02 03:34:37 +00:00
|
|
|
for platform in PLATFORMS:
|
|
|
|
hass.async_create_task(
|
|
|
|
hass.config_entries.async_forward_entry_setup(config_entry, platform)
|
|
|
|
)
|
2020-05-16 15:53:11 +00:00
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
|
|
|
|
"""Unload Gogogate2 config entry."""
|
2021-03-02 03:34:37 +00:00
|
|
|
unload_ok = all(
|
|
|
|
await asyncio.gather(
|
|
|
|
*[
|
|
|
|
hass.config_entries.async_forward_entry_unload(config_entry, platform)
|
|
|
|
for platform in PLATFORMS
|
|
|
|
]
|
|
|
|
)
|
2020-05-16 15:53:11 +00:00
|
|
|
)
|
|
|
|
|
2021-03-02 03:34:37 +00:00
|
|
|
return unload_ok
|