Skip to content

Commit

Permalink
Split opentherm_gw entity base class (#125330)
Browse files Browse the repository at this point in the history
Add OpenThermStatusEntity to allow entities that don't need status updates
  • Loading branch information
mvn23 authored Sep 5, 2024
1 parent 70966c2 commit 65e16b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 23 deletions.
4 changes: 2 additions & 2 deletions homeassistant/components/opentherm_gw/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THERMOSTAT_DEVICE_DESCRIPTION,
OpenThermDataSource,
)
from .entity import OpenThermEntity, OpenThermEntityDescription
from .entity import OpenThermEntityDescription, OpenThermStatusEntity


@dataclass(frozen=True, kw_only=True)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 2 additions & 12 deletions homeassistant/components/opentherm_gw/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions homeassistant/components/opentherm_gw/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
THERMOSTAT_DEVICE_DESCRIPTION,
OpenThermDataSource,
)
from .entity import OpenThermEntity, OpenThermEntityDescription
from .entity import OpenThermEntityDescription, OpenThermStatusEntity

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -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 = (
Expand Down
14 changes: 9 additions & 5 deletions homeassistant/components/opentherm_gw/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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."""
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/opentherm_gw/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
THERMOSTAT_DEVICE_DESCRIPTION,
OpenThermDataSource,
)
from .entity import OpenThermEntity, OpenThermEntityDescription
from .entity import OpenThermEntityDescription, OpenThermStatusEntity

SENSOR_FLOAT_SUGGESTED_DISPLAY_PRECISION = 1

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 65e16b4

Please sign in to comment.