mirror of
https://github.com/home-assistant/core.git
synced 2026-07-01 03:36:05 +01:00
be2aaf926b
Co-authored-by: Joostlek <joostlek@outlook.com>
43 lines
1.3 KiB
Python
43 lines
1.3 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.aiohttp_client import async_get_clientsession
|
|
|
|
from .coordinator import YardianConfigEntry, YardianUpdateCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [
|
|
Platform.BINARY_SENSOR,
|
|
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
|
|
|
|
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)
|