mirror of
https://github.com/Gurkengewuerz/casait-has.git
synced 2025-01-18 15:36:28 +01:00
63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
|
"""The Smart Home integration."""
|
||
|
from __future__ import annotations
|
||
|
|
||
|
import logging
|
||
|
from typing import Any
|
||
|
|
||
|
import voluptuous as vol
|
||
|
|
||
|
from homeassistant.config_entries import ConfigEntry
|
||
|
from homeassistant.const import Platform, CONF_HOST, CONF_PORT, CONF_NAME
|
||
|
from homeassistant.core import HomeAssistant, callback
|
||
|
from homeassistant.helpers import device_registry as dr
|
||
|
|
||
|
from .const import (
|
||
|
DOMAIN,
|
||
|
DATA_COORDINATOR,
|
||
|
DATA_CONFIG,
|
||
|
DEFAULT_PORT,
|
||
|
DEVICE_TYPE_MAPPING,
|
||
|
)
|
||
|
from .coordinator import SmartHomeDataUpdateCoordinator
|
||
|
|
||
|
_LOGGER = logging.getLogger(__name__)
|
||
|
|
||
|
PLATFORMS: list[Platform] = [
|
||
|
Platform.SWITCH,
|
||
|
Platform.BUTTON,
|
||
|
Platform.COVER,
|
||
|
Platform.SENSOR,
|
||
|
Platform.BINARY_SENSOR,
|
||
|
]
|
||
|
|
||
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||
|
"""Set up Smart Home from a config entry."""
|
||
|
hass.data.setdefault(DOMAIN, {})
|
||
|
|
||
|
coordinator = SmartHomeDataUpdateCoordinator(
|
||
|
hass,
|
||
|
config=entry.data,
|
||
|
entry_id=entry.entry_id,
|
||
|
)
|
||
|
|
||
|
await coordinator.async_config_entry_first_refresh()
|
||
|
|
||
|
hass.data[DOMAIN][entry.entry_id] = {
|
||
|
DATA_COORDINATOR: coordinator,
|
||
|
DATA_CONFIG: entry.data,
|
||
|
}
|
||
|
|
||
|
await hass.config_entries.async_forward_entry_setups(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:
|
||
|
coordinator: SmartHomeDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR]
|
||
|
await coordinator.async_shutdown()
|
||
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||
|
|
||
|
return unload_ok
|