mirror of
https://github.com/home-assistant/core.git
synced 2026-08-16 10:13:55 +01:00
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""The Yardian integration."""
|
|
|
|
from pyyardian import AsyncYardianClient
|
|
|
|
from homeassistant.const import CONF_ACCESS_TOKEN, CONF_HOST, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers import device_registry as dr
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from .coordinator import YardianConfigEntry, YardianUpdateCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [
|
|
Platform.BINARY_SENSOR,
|
|
Platform.BUTTON,
|
|
Platform.SENSOR,
|
|
Platform.SWITCH,
|
|
]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: YardianConfigEntry) -> bool:
|
|
"""Set up Yardian from a config entry."""
|
|
|
|
host = entry.data[CONF_HOST]
|
|
access_token = entry.data[CONF_ACCESS_TOKEN]
|
|
|
|
# Change this line to use .create()
|
|
# This ensures the coordinator's controller knows if it is YP or YC
|
|
controller = await AsyncYardianClient.create(
|
|
async_get_clientsession(hass), host, token=access_token
|
|
)
|
|
|
|
coordinator = YardianUpdateCoordinator(hass, entry, controller)
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
entry.runtime_data = coordinator
|
|
|
|
# Register the main device so zone child devices can resolve it as their
|
|
# via_device regardless of platform setup order.
|
|
dr.async_get(hass).async_get_or_create(
|
|
config_entry_id=entry.entry_id,
|
|
**coordinator.device_info,
|
|
)
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(hass: HomeAssistant, entry: YardianConfigEntry) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|