2021-09-29 15:43:51 +00:00
|
|
|
"""The OpenGarage integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import opengarage
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_VERIFY_SSL
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
|
|
|
|
from .const import CONF_DEVICE_KEY, DOMAIN
|
|
|
|
|
|
|
|
PLATFORMS = ["cover"]
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Set up OpenGarage from a config entry."""
|
|
|
|
hass.data.setdefault(DOMAIN, {})
|
|
|
|
|
|
|
|
hass.data[DOMAIN][entry.entry_id] = opengarage.OpenGarage(
|
|
|
|
f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}",
|
|
|
|
entry.data[CONF_DEVICE_KEY],
|
|
|
|
entry.data[CONF_VERIFY_SSL],
|
|
|
|
async_get_clientsession(hass),
|
|
|
|
)
|
|
|
|
|
|
|
|
hass.config_entries.async_setup_platforms(entry, PLATFORMS)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Unload a config entry."""
|
|
|
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
|
|
|
if unload_ok:
|
|
|
|
hass.data[DOMAIN].pop(entry.entry_id)
|
|
|
|
|
|
|
|
return unload_ok
|