2022-02-23 18:15:04 +00:00
|
|
|
"""Support for Overkiz climate devices."""
|
2024-03-08 14:04:07 +00:00
|
|
|
|
2022-02-23 18:15:04 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import Platform
|
|
|
|
from homeassistant.core import HomeAssistant
|
2024-03-29 13:51:44 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2022-02-23 18:15:04 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
|
|
|
|
from . import HomeAssistantOverkizData
|
2023-11-24 14:00:36 +00:00
|
|
|
from .climate_entities import (
|
2024-02-28 22:16:03 +00:00
|
|
|
WIDGET_AND_CONTROLLABLE_TO_CLIMATE_ENTITY,
|
2023-11-24 14:00:36 +00:00
|
|
|
WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY,
|
|
|
|
WIDGET_TO_CLIMATE_ENTITY,
|
|
|
|
)
|
2022-02-23 18:15:04 +00:00
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up the Overkiz climate from a config entry."""
|
|
|
|
data: HomeAssistantOverkizData = hass.data[DOMAIN][entry.entry_id]
|
|
|
|
|
2024-03-29 13:51:44 +00:00
|
|
|
# Match devices based on the widget.
|
|
|
|
entities_based_on_widget: list[Entity] = [
|
2022-02-23 18:15:04 +00:00
|
|
|
WIDGET_TO_CLIMATE_ENTITY[device.widget](device.device_url, data.coordinator)
|
|
|
|
for device in data.platforms[Platform.CLIMATE]
|
|
|
|
if device.widget in WIDGET_TO_CLIMATE_ENTITY
|
2024-03-29 13:51:44 +00:00
|
|
|
]
|
2023-11-24 14:00:36 +00:00
|
|
|
|
2024-03-29 13:51:44 +00:00
|
|
|
# Match devices based on the widget and controllableName.
|
|
|
|
# ie Atlantic APC
|
|
|
|
entities_based_on_widget_and_controllable: list[Entity] = [
|
2024-02-28 22:16:03 +00:00
|
|
|
WIDGET_AND_CONTROLLABLE_TO_CLIMATE_ENTITY[device.widget][
|
2024-07-25 19:48:10 +00:00
|
|
|
device.controllable_name
|
2024-02-28 22:16:03 +00:00
|
|
|
](device.device_url, data.coordinator)
|
|
|
|
for device in data.platforms[Platform.CLIMATE]
|
|
|
|
if device.widget in WIDGET_AND_CONTROLLABLE_TO_CLIMATE_ENTITY
|
|
|
|
and device.controllable_name
|
|
|
|
in WIDGET_AND_CONTROLLABLE_TO_CLIMATE_ENTITY[device.widget]
|
2024-03-29 13:51:44 +00:00
|
|
|
]
|
2024-02-28 22:16:03 +00:00
|
|
|
|
2024-03-29 13:51:44 +00:00
|
|
|
# Match devices based on the widget and protocol.
|
|
|
|
# #ie Hitachi Air To Air Heat Pumps
|
|
|
|
entities_based_on_widget_and_protocol: list[Entity] = [
|
2023-11-24 14:00:36 +00:00
|
|
|
WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY[device.widget][device.protocol](
|
|
|
|
device.device_url, data.coordinator
|
|
|
|
)
|
|
|
|
for device in data.platforms[Platform.CLIMATE]
|
|
|
|
if device.widget in WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY
|
|
|
|
and device.protocol in WIDGET_AND_PROTOCOL_TO_CLIMATE_ENTITY[device.widget]
|
2024-03-29 13:51:44 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
async_add_entities(
|
|
|
|
entities_based_on_widget
|
|
|
|
+ entities_based_on_widget_and_controllable
|
|
|
|
+ entities_based_on_widget_and_protocol
|
2023-11-24 14:00:36 +00:00
|
|
|
)
|