2024-08-20 08:20:27 +00:00
|
|
|
"""Common opentherm_gw entity properties."""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2024-08-20 12:51:08 +00:00
|
|
|
import pyotgw.vars as gw_vars
|
|
|
|
|
2024-08-20 08:20:27 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
|
|
from homeassistant.helpers.entity import Entity, EntityDescription
|
|
|
|
|
|
|
|
from . import OpenThermGatewayDevice
|
2024-08-20 12:51:08 +00:00
|
|
|
from .const import DOMAIN
|
2024-08-20 08:20:27 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2024-08-20 12:51:08 +00:00
|
|
|
TRANSLATE_SOURCE = {
|
|
|
|
gw_vars.BOILER: "Boiler",
|
|
|
|
gw_vars.OTGW: None,
|
|
|
|
gw_vars.THERMOSTAT: "Thermostat",
|
|
|
|
}
|
|
|
|
|
2024-08-20 08:20:27 +00:00
|
|
|
|
|
|
|
class OpenThermEntityDescription(EntityDescription):
|
|
|
|
"""Describe common opentherm_gw entity properties."""
|
|
|
|
|
|
|
|
friendly_name_format: str
|
|
|
|
|
|
|
|
|
|
|
|
class OpenThermEntity(Entity):
|
|
|
|
"""Represent an OpenTherm Gateway entity."""
|
|
|
|
|
|
|
|
_attr_should_poll = False
|
|
|
|
_attr_entity_registry_enabled_default = False
|
|
|
|
_attr_available = False
|
|
|
|
entity_description: OpenThermEntityDescription
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
gw_dev: OpenThermGatewayDevice,
|
|
|
|
source: str,
|
|
|
|
description: OpenThermEntityDescription,
|
|
|
|
) -> None:
|
|
|
|
"""Initialize the entity."""
|
|
|
|
self.entity_description = description
|
|
|
|
self._gateway = gw_dev
|
|
|
|
self._source = source
|
|
|
|
friendly_name_format = (
|
|
|
|
f"{description.friendly_name_format} ({TRANSLATE_SOURCE[source]})"
|
|
|
|
if TRANSLATE_SOURCE[source] is not None
|
|
|
|
else description.friendly_name_format
|
|
|
|
)
|
|
|
|
self._attr_name = friendly_name_format.format(gw_dev.name)
|
|
|
|
self._attr_unique_id = f"{gw_dev.gw_id}-{source}-{description.key}"
|
|
|
|
self._attr_device_info = DeviceInfo(
|
|
|
|
identifiers={(DOMAIN, gw_dev.gw_id)},
|
|
|
|
manufacturer="Schelte Bron",
|
|
|
|
model="OpenTherm Gateway",
|
|
|
|
name=gw_dev.name,
|
|
|
|
sw_version=gw_dev.gw_version,
|
|
|
|
)
|
|
|
|
|
|
|
|
async def async_added_to_hass(self) -> None:
|
|
|
|
"""Subscribe to updates from the component."""
|
|
|
|
_LOGGER.debug("Added OpenTherm Gateway entity %s", self._attr_name)
|
|
|
|
self.async_on_remove(
|
|
|
|
async_dispatcher_connect(
|
|
|
|
self.hass, self._gateway.update_signal, self.receive_report
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
@callback
|
|
|
|
def receive_report(self, status: dict[str, dict]) -> None:
|
|
|
|
"""Handle status updates from the component."""
|
|
|
|
# Must be implemented at the platform level.
|
|
|
|
raise NotImplementedError
|