mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
Add binary sensor platform to eq3btsmart (#130352)
This commit is contained in:
parent
5293fc73d8
commit
829632b0af
@ -19,6 +19,7 @@ from .const import SIGNAL_THERMOSTAT_CONNECTED, SIGNAL_THERMOSTAT_DISCONNECTED
|
||||
from .models import Eq3Config, Eq3ConfigEntryData
|
||||
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.CLIMATE,
|
||||
]
|
||||
|
||||
|
86
homeassistant/components/eq3btsmart/binary_sensor.py
Normal file
86
homeassistant/components/eq3btsmart/binary_sensor.py
Normal file
@ -0,0 +1,86 @@
|
||||
"""Platform for eq3 binary sensor entities."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from eq3btsmart.models import Status
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
||||
from . import Eq3ConfigEntry
|
||||
from .const import ENTITY_KEY_BATTERY, ENTITY_KEY_DST, ENTITY_KEY_WINDOW
|
||||
from .entity import Eq3Entity
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class Eq3BinarySensorEntityDescription(BinarySensorEntityDescription):
|
||||
"""Entity description for eq3 binary sensors."""
|
||||
|
||||
value_func: Callable[[Status], bool]
|
||||
|
||||
|
||||
BINARY_SENSOR_ENTITY_DESCRIPTIONS = [
|
||||
Eq3BinarySensorEntityDescription(
|
||||
value_func=lambda status: status.is_low_battery,
|
||||
key=ENTITY_KEY_BATTERY,
|
||||
device_class=BinarySensorDeviceClass.BATTERY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
Eq3BinarySensorEntityDescription(
|
||||
value_func=lambda status: status.is_window_open,
|
||||
key=ENTITY_KEY_WINDOW,
|
||||
device_class=BinarySensorDeviceClass.WINDOW,
|
||||
),
|
||||
Eq3BinarySensorEntityDescription(
|
||||
value_func=lambda status: status.is_dst,
|
||||
key=ENTITY_KEY_DST,
|
||||
translation_key=ENTITY_KEY_DST,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
]
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: Eq3ConfigEntry,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the entry."""
|
||||
|
||||
async_add_entities(
|
||||
Eq3BinarySensorEntity(entry, entity_description)
|
||||
for entity_description in BINARY_SENSOR_ENTITY_DESCRIPTIONS
|
||||
)
|
||||
|
||||
|
||||
class Eq3BinarySensorEntity(Eq3Entity, BinarySensorEntity):
|
||||
"""Base class for eQ-3 binary sensor entities."""
|
||||
|
||||
entity_description: Eq3BinarySensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
entry: Eq3ConfigEntry,
|
||||
entity_description: Eq3BinarySensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialize the entity."""
|
||||
|
||||
super().__init__(entry, entity_description.key)
|
||||
self.entity_description = entity_description
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return the state of the binary sensor."""
|
||||
|
||||
if TYPE_CHECKING:
|
||||
assert self._thermostat.status is not None
|
||||
|
||||
return self.entity_description.value_func(self._thermostat.status)
|
@ -18,6 +18,10 @@ DOMAIN = "eq3btsmart"
|
||||
MANUFACTURER = "eQ-3 AG"
|
||||
DEVICE_MODEL = "CC-RT-BLE-EQ"
|
||||
|
||||
ENTITY_KEY_DST = "dst"
|
||||
ENTITY_KEY_BATTERY = "battery"
|
||||
ENTITY_KEY_WINDOW = "window"
|
||||
|
||||
GET_DEVICE_TIMEOUT = 5 # seconds
|
||||
|
||||
EQ_TO_HA_HVAC: dict[OperationMode, HVACMode] = {
|
||||
|
@ -24,7 +24,11 @@ class Eq3Entity(Entity):
|
||||
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, entry: Eq3ConfigEntry, unique_id_key: str | None = None) -> None:
|
||||
def __init__(
|
||||
self,
|
||||
entry: Eq3ConfigEntry,
|
||||
unique_id_key: str | None = None,
|
||||
) -> None:
|
||||
"""Initialize the eq3 entity."""
|
||||
|
||||
self._eq3_config = entry.runtime_data.eq3_config
|
||||
@ -81,3 +85,9 @@ class Eq3Entity(Entity):
|
||||
|
||||
self._attr_available = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def available(self) -> bool:
|
||||
"""Whether the entity is available."""
|
||||
|
||||
return self._thermostat.status is not None and self._attr_available
|
||||
|
@ -18,5 +18,12 @@
|
||||
"error": {
|
||||
"invalid_mac_address": "Invalid MAC address"
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"dst": {
|
||||
"name": "Daylight saving time"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user