mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Split opentherm_gw entity base class (#125330)
Add OpenThermStatusEntity to allow entities that don't need status updates
This commit is contained in:
parent
70966c2b63
commit
65e16b4814
@ -22,7 +22,7 @@ from .const import (
|
|||||||
THERMOSTAT_DEVICE_DESCRIPTION,
|
THERMOSTAT_DEVICE_DESCRIPTION,
|
||||||
OpenThermDataSource,
|
OpenThermDataSource,
|
||||||
)
|
)
|
||||||
from .entity import OpenThermEntity, OpenThermEntityDescription
|
from .entity import OpenThermEntityDescription, OpenThermStatusEntity
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@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."""
|
"""Represent an OpenTherm Gateway binary sensor."""
|
||||||
|
|
||||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||||
|
@ -12,16 +12,11 @@ from homeassistant.components.button import (
|
|||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_ID, EntityCategory
|
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 homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from . import OpenThermGatewayHub
|
from . import OpenThermGatewayHub
|
||||||
from .const import (
|
from .const import DATA_GATEWAYS, DATA_OPENTHERM_GW, GATEWAY_DEVICE_DESCRIPTION
|
||||||
DATA_GATEWAYS,
|
|
||||||
DATA_OPENTHERM_GW,
|
|
||||||
GATEWAY_DEVICE_DESCRIPTION,
|
|
||||||
OpenThermDataSource,
|
|
||||||
)
|
|
||||||
from .entity import OpenThermEntity, OpenThermEntityDescription
|
from .entity import OpenThermEntity, OpenThermEntityDescription
|
||||||
|
|
||||||
|
|
||||||
@ -63,11 +58,6 @@ class OpenThermButton(OpenThermEntity, ButtonEntity):
|
|||||||
_attr_entity_category = EntityCategory.CONFIG
|
_attr_entity_category = EntityCategory.CONFIG
|
||||||
entity_description: OpenThermButtonEntityDescription
|
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:
|
async def async_press(self) -> None:
|
||||||
"""Perform button action."""
|
"""Perform button action."""
|
||||||
await self.entity_description.action(self._gateway)
|
await self.entity_description.action(self._gateway)
|
||||||
|
@ -34,7 +34,7 @@ from .const import (
|
|||||||
THERMOSTAT_DEVICE_DESCRIPTION,
|
THERMOSTAT_DEVICE_DESCRIPTION,
|
||||||
OpenThermDataSource,
|
OpenThermDataSource,
|
||||||
)
|
)
|
||||||
from .entity import OpenThermEntity, OpenThermEntityDescription
|
from .entity import OpenThermEntityDescription, OpenThermStatusEntity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ async def async_setup_entry(
|
|||||||
async_add_entities(ents)
|
async_add_entities(ents)
|
||||||
|
|
||||||
|
|
||||||
class OpenThermClimate(OpenThermEntity, ClimateEntity):
|
class OpenThermClimate(OpenThermStatusEntity, ClimateEntity):
|
||||||
"""Representation of a climate device."""
|
"""Representation of a climate device."""
|
||||||
|
|
||||||
_attr_supported_features = (
|
_attr_supported_features = (
|
||||||
|
@ -52,6 +52,15 @@ class OpenThermEntity(Entity):
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@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:
|
async def async_added_to_hass(self) -> None:
|
||||||
"""Subscribe to updates from the component."""
|
"""Subscribe to updates from the component."""
|
||||||
self.async_on_remove(
|
self.async_on_remove(
|
||||||
@ -60,11 +69,6 @@ class OpenThermEntity(Entity):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
|
||||||
def available(self) -> bool:
|
|
||||||
"""Return connection status of the hub to indicate availability."""
|
|
||||||
return self._gateway.connected
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def receive_report(self, status: dict[OpenThermDataSource, dict]) -> None:
|
def receive_report(self, status: dict[OpenThermDataSource, dict]) -> None:
|
||||||
"""Handle status updates from the component."""
|
"""Handle status updates from the component."""
|
||||||
|
@ -32,7 +32,7 @@ from .const import (
|
|||||||
THERMOSTAT_DEVICE_DESCRIPTION,
|
THERMOSTAT_DEVICE_DESCRIPTION,
|
||||||
OpenThermDataSource,
|
OpenThermDataSource,
|
||||||
)
|
)
|
||||||
from .entity import OpenThermEntity, OpenThermEntityDescription
|
from .entity import OpenThermEntityDescription, OpenThermStatusEntity
|
||||||
|
|
||||||
SENSOR_FLOAT_SUGGESTED_DISPLAY_PRECISION = 1
|
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."""
|
"""Representation of an OpenTherm sensor."""
|
||||||
|
|
||||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||||
|
Loading…
x
Reference in New Issue
Block a user