ha_gehome/custom_components/ge_home/__init__.py

47 lines
1.3 KiB
Python
Raw Normal View History

"""The ge_home integration."""
2020-08-12 09:03:22 -06:00
from homeassistant.const import EVENT_HOMEASSISTANT_STOP
2020-08-12 09:03:22 -06:00
import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
2020-08-12 09:03:22 -06:00
from homeassistant.core import HomeAssistant
from .const import DOMAIN
from .update_coordinator import GeHomeUpdateCoordinator
2020-08-12 09:03:22 -06:00
2020-08-13 15:10:55 -06:00
CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA)
2020-08-12 09:03:22 -06:00
2020-08-12 09:03:22 -06:00
async def async_setup(hass: HomeAssistant, config: dict):
return True
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up the ge_home component."""
2020-08-13 15:10:55 -06:00
hass.data.setdefault(DOMAIN, {})
2020-08-12 09:03:22 -06:00
"""Set up ge_home from a config entry."""
coordinator = GeHomeUpdateCoordinator(hass, entry)
2020-08-13 15:10:55 -06:00
hass.data[DOMAIN][entry.entry_id] = coordinator
2020-08-12 09:03:22 -06:00
if not await coordinator.async_setup():
return False
2020-08-12 09:03:22 -06:00
hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, coordinator.shutdown)
2020-08-12 09:03:22 -06:00
return True
2020-08-12 09:03:22 -06:00
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Unload a config entry."""
coordinator: GeHomeUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
ok = await coordinator.async_reset()
if ok:
2020-08-12 09:03:22 -06:00
hass.data[DOMAIN].pop(entry.entry_id)
return ok
2020-08-25 11:09:28 -06:00
2020-08-25 11:09:28 -06:00
async def async_update_options(hass, config_entry):
"""Update options."""
await hass.config_entries.async_reload(config_entry.entry_id)