From 65e16b4814412df938f1109e5b56f3d15f5f9e0b Mon Sep 17 00:00:00 2001 From: mvn23 Date: Thu, 5 Sep 2024 13:03:16 +0200 Subject: [PATCH] Split opentherm_gw entity base class (#125330) Add OpenThermStatusEntity to allow entities that don't need status updates --- .../components/opentherm_gw/binary_sensor.py | 4 ++-- homeassistant/components/opentherm_gw/button.py | 14 ++------------ homeassistant/components/opentherm_gw/climate.py | 4 ++-- homeassistant/components/opentherm_gw/entity.py | 14 +++++++++----- homeassistant/components/opentherm_gw/sensor.py | 4 ++-- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/opentherm_gw/binary_sensor.py b/homeassistant/components/opentherm_gw/binary_sensor.py index 00885a18088de..5d542bedc074e 100644 --- a/homeassistant/components/opentherm_gw/binary_sensor.py +++ b/homeassistant/components/opentherm_gw/binary_sensor.py @@ -22,7 +22,7 @@ THERMOSTAT_DEVICE_DESCRIPTION, OpenThermDataSource, ) -from .entity import OpenThermEntity, OpenThermEntityDescription +from .entity import OpenThermEntityDescription, OpenThermStatusEntity @dataclass(frozen=True, kw_only=True) @@ -404,7 +404,7 @@ async def async_setup_entry( ) -class OpenThermBinarySensor(OpenThermEntity, BinarySensorEntity): +class OpenThermBinarySensor(OpenThermStatusEntity, BinarySensorEntity): """Represent an OpenTherm Gateway binary sensor.""" _attr_entity_category = EntityCategory.DIAGNOSTIC diff --git a/homeassistant/components/opentherm_gw/button.py b/homeassistant/components/opentherm_gw/button.py index aa0a3dbcda5aa..bac50295199ab 100644 --- a/homeassistant/components/opentherm_gw/button.py +++ b/homeassistant/components/opentherm_gw/button.py @@ -12,16 +12,11 @@ ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ID, EntityCategory -from homeassistant.core import HomeAssistant, callback +from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import OpenThermGatewayHub -from .const import ( - DATA_GATEWAYS, - DATA_OPENTHERM_GW, - GATEWAY_DEVICE_DESCRIPTION, - OpenThermDataSource, -) +from .const import DATA_GATEWAYS, DATA_OPENTHERM_GW, GATEWAY_DEVICE_DESCRIPTION from .entity import OpenThermEntity, OpenThermEntityDescription @@ -63,11 +58,6 @@ class OpenThermButton(OpenThermEntity, ButtonEntity): _attr_entity_category = EntityCategory.CONFIG entity_description: OpenThermButtonEntityDescription - @callback - def receive_report(self, status: dict[OpenThermDataSource, dict]) -> None: - """Handle status updates from the component.""" - # We don't need any information from the reports here - async def async_press(self) -> None: """Perform button action.""" await self.entity_description.action(self._gateway) diff --git a/homeassistant/components/opentherm_gw/climate.py b/homeassistant/components/opentherm_gw/climate.py index 45f1ca478f5ef..6edfeb35ec3fc 100644 --- a/homeassistant/components/opentherm_gw/climate.py +++ b/homeassistant/components/opentherm_gw/climate.py @@ -34,7 +34,7 @@ THERMOSTAT_DEVICE_DESCRIPTION, OpenThermDataSource, ) -from .entity import OpenThermEntity, OpenThermEntityDescription +from .entity import OpenThermEntityDescription, OpenThermStatusEntity _LOGGER = logging.getLogger(__name__) @@ -69,7 +69,7 @@ async def async_setup_entry( async_add_entities(ents) -class OpenThermClimate(OpenThermEntity, ClimateEntity): +class OpenThermClimate(OpenThermStatusEntity, ClimateEntity): """Representation of a climate device.""" _attr_supported_features = ( diff --git a/homeassistant/components/opentherm_gw/entity.py b/homeassistant/components/opentherm_gw/entity.py index b7110fa9e1bed..e87a6c182aa13 100644 --- a/homeassistant/components/opentherm_gw/entity.py +++ b/homeassistant/components/opentherm_gw/entity.py @@ -52,6 +52,15 @@ def __init__( }, ) + @property + def available(self) -> bool: + """Return connection status of the hub to indicate availability.""" + return self._gateway.connected + + +class OpenThermStatusEntity(OpenThermEntity): + """Represent an OpenTherm entity that receives status updates.""" + async def async_added_to_hass(self) -> None: """Subscribe to updates from the component.""" self.async_on_remove( @@ -60,11 +69,6 @@ async def async_added_to_hass(self) -> None: ) ) - @property - def available(self) -> bool: - """Return connection status of the hub to indicate availability.""" - return self._gateway.connected - @callback def receive_report(self, status: dict[OpenThermDataSource, dict]) -> None: """Handle status updates from the component.""" diff --git a/homeassistant/components/opentherm_gw/sensor.py b/homeassistant/components/opentherm_gw/sensor.py index eeadd5c4ee173..5ccb4166665da 100644 --- a/homeassistant/components/opentherm_gw/sensor.py +++ b/homeassistant/components/opentherm_gw/sensor.py @@ -32,7 +32,7 @@ THERMOSTAT_DEVICE_DESCRIPTION, OpenThermDataSource, ) -from .entity import OpenThermEntity, OpenThermEntityDescription +from .entity import OpenThermEntityDescription, OpenThermStatusEntity SENSOR_FLOAT_SUGGESTED_DISPLAY_PRECISION = 1 @@ -889,7 +889,7 @@ async def async_setup_entry( ) -class OpenThermSensor(OpenThermEntity, SensorEntity): +class OpenThermSensor(OpenThermStatusEntity, SensorEntity): """Representation of an OpenTherm sensor.""" _attr_entity_category = EntityCategory.DIAGNOSTIC