2021-09-29 15:43:51 +00:00
|
|
|
"""The OpenGarage integration."""
|
2024-03-08 14:04:07 +00:00
|
|
|
|
2021-09-29 15:43:51 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import opengarage
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2021-12-06 03:06:35 +00:00
|
|
|
from homeassistant.const import CONF_HOST, CONF_PORT, CONF_VERIFY_SSL, Platform
|
2021-09-29 15:43:51 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
|
|
|
|
from .const import CONF_DEVICE_KEY, DOMAIN
|
2024-05-17 06:05:43 +00:00
|
|
|
from .coordinator import OpenGarageDataUpdateCoordinator
|
2021-10-17 17:48:45 +00:00
|
|
|
|
2024-01-04 06:37:24 +00:00
|
|
|
PLATFORMS = [Platform.BINARY_SENSOR, Platform.BUTTON, Platform.COVER, Platform.SENSOR]
|
2021-09-29 15:43:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|
|
|
"""Set up OpenGarage from a config entry."""
|
2021-10-17 17:48:45 +00:00
|
|
|
open_garage_connection = opengarage.OpenGarage(
|
2021-09-29 15:43:51 +00:00
|
|
|
f"{entry.data[CONF_HOST]}:{entry.data[CONF_PORT]}",
|
|
|
|
entry.data[CONF_DEVICE_KEY],
|
|
|
|
entry.data[CONF_VERIFY_SSL],
|
|
|
|
async_get_clientsession(hass),
|
|
|
|
)
|
2021-10-17 17:48:45 +00:00
|
|
|
open_garage_data_coordinator = OpenGarageDataUpdateCoordinator(
|
|
|
|
hass,
|
|
|
|
open_garage_connection=open_garage_connection,
|
|
|
|
)
|
|
|
|
await open_garage_data_coordinator.async_config_entry_first_refresh()
|
2024-01-04 06:37:24 +00:00
|
|
|
hass.data.setdefault(DOMAIN, {})[entry.entry_id] = open_garage_data_coordinator
|
2021-09-29 15:43:51 +00:00
|
|
|
|
2022-07-09 15:27:42 +00:00
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
2021-09-29 15:43:51 +00:00
|
|
|
|
|
|
|
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
|