56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
|
"""The Immersive Home integration."""
|
||
|
|
||
|
from __future__ import annotations
|
||
|
|
||
|
from homeassistant.config_entries import ConfigEntry
|
||
|
from homeassistant.const import Platform
|
||
|
from homeassistant.core import HomeAssistant
|
||
|
from homeassistant.helpers import device_registry as dr
|
||
|
from homeassistant.helpers.typing import ConfigType
|
||
|
|
||
|
from . import hub, websocket_api
|
||
|
from .const import DOMAIN
|
||
|
|
||
|
PLATFORMS: list[Platform] = [Platform.SENSOR]
|
||
|
|
||
|
|
||
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||
|
"""Set up the ImmersiveHome component."""
|
||
|
|
||
|
hass.data[DOMAIN] = {
|
||
|
"hub": hub.Hub(hass),
|
||
|
}
|
||
|
|
||
|
websocket_api.async_setup_commands(hass)
|
||
|
return True
|
||
|
|
||
|
|
||
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||
|
"""Set up ImmersiveHome from a config entry."""
|
||
|
registration = entry.data
|
||
|
|
||
|
hass.data.setdefault(DOMAIN, {})
|
||
|
|
||
|
device_registry = dr.async_get(hass)
|
||
|
|
||
|
device_registry.async_get_or_create(
|
||
|
config_entry_id=entry.entry_id,
|
||
|
identifiers={(DOMAIN, registration["device_id"])},
|
||
|
manufacturer="Someone",
|
||
|
model=registration["platform"],
|
||
|
name=registration["name"],
|
||
|
sw_version=registration["version"],
|
||
|
)
|
||
|
|
||
|
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."""
|
||
|
if unload_ok := await hass.config_entries.async_unload_platforms(entry, PLATFORMS):
|
||
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||
|
|
||
|
return unload_ok
|