Add missing binary sensors to Hive integration (#122296)

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors

* add missing sensors
pull/122427/head^2
ribbal 2024-07-22 22:15:36 +01:00 committed by GitHub
parent 3df6b34a03
commit ba276a5cb6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 71 additions and 10 deletions

View File

@ -47,6 +47,25 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
),
)
SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription(
key="Heating_State",
translation_key="heating",
),
BinarySensorEntityDescription(
key="Heating_Boost",
translation_key="heating",
),
BinarySensorEntityDescription(
key="Hotwater_State",
translation_key="hot_water",
),
BinarySensorEntityDescription(
key="Hotwater_Boost",
translation_key="hot_water",
),
)
async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
@ -54,19 +73,27 @@ async def async_setup_entry(
"""Set up Hive thermostat based on a config entry."""
hive = hass.data[DOMAIN][entry.entry_id]
sensors: list[BinarySensorEntity] = []
devices = hive.session.deviceList.get("binary_sensor")
if not devices:
return
async_add_entities(
(
HiveBinarySensorEntity(hive, dev, description)
for dev in devices
for description in BINARY_SENSOR_TYPES
if dev["hiveType"] == description.key
),
True,
sensors.extend(
HiveBinarySensorEntity(hive, dev, description)
for dev in devices
for description in BINARY_SENSOR_TYPES
if dev["hiveType"] == description.key
)
devices = hive.session.deviceList.get("sensor")
sensors.extend(
HiveSensorEntity(hive, dev, description)
for dev in devices
for description in SENSOR_TYPES
if dev["hiveType"] == description.key
)
async_add_entities(sensors, True)
class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
"""Representation of a Hive binary sensor."""
@ -91,3 +118,24 @@ class HiveBinarySensorEntity(HiveEntity, BinarySensorEntity):
self._attr_available = self.device["deviceData"].get("online")
else:
self._attr_available = True
class HiveSensorEntity(HiveEntity, BinarySensorEntity):
"""Hive Sensor Entity."""
def __init__(
self,
hive: Hive,
hive_device: dict[str, Any],
entity_description: BinarySensorEntityDescription,
) -> None:
"""Initialise hive sensor."""
super().__init__(hive, hive_device)
self.entity_description = entity_description
async def async_update(self) -> None:
"""Update all Node data from Hive."""
await self.hive.session.updateData(self.device)
self.device = await self.hive.sensor.getSensor(self.device)
self._attr_is_on = self.device["status"]["state"] == "ON"
self._attr_available = self.device["deviceData"].get("online")

View File

@ -1,4 +1,17 @@
{
"entity": {
"binary_sensor": {
"heating": {
"default": "mdi:radiator"
},
"hot_water": {
"default": "mdi:hand-water"
},
"temperature": {
"default": "mdi:thermometer"
}
}
},
"services": {
"boost_heating_on": "mdi:radiator",
"boost_heating_off": "mdi:radiator-off",