Create additional sensors in Hive integration (#122453)

* 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

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors

* add temperature and mode sensors
This commit is contained in:
ribbal 2024-07-23 18:21:58 +01:00 committed by GitHub
parent 6bdc5be433
commit 1b7fb9ae12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 72 additions and 8 deletions

View File

@ -6,9 +6,14 @@
}, },
"hot_water": { "hot_water": {
"default": "mdi:hand-water" "default": "mdi:hand-water"
}
}, },
"temperature": { "sensor": {
"default": "mdi:thermometer" "heating": {
"default": "mdi:radiator"
},
"hot_water": {
"default": "mdi:hand-water"
} }
} }
}, },

View File

@ -1,5 +1,7 @@
"""Support for the Hive sensors.""" """Support for the Hive sensors."""
from collections.abc import Callable
from dataclasses import dataclass
from datetime import timedelta from datetime import timedelta
from typing import Any from typing import Any
@ -20,6 +22,7 @@ from homeassistant.const import (
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from . import HiveEntity from . import HiveEntity
from .const import DOMAIN from .const import DOMAIN
@ -27,27 +30,61 @@ from .const import DOMAIN
PARALLEL_UPDATES = 0 PARALLEL_UPDATES = 0
SCAN_INTERVAL = timedelta(seconds=15) SCAN_INTERVAL = timedelta(seconds=15)
SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
SensorEntityDescription( @dataclass(frozen=True)
class HiveSensorEntityDescription(SensorEntityDescription):
"""Describes Hive sensor entity."""
fn: Callable[[StateType], StateType] = lambda x: x
SENSOR_TYPES: tuple[HiveSensorEntityDescription, ...] = (
HiveSensorEntityDescription(
key="Battery", key="Battery",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY, device_class=SensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
SensorEntityDescription( HiveSensorEntityDescription(
key="Power", key="Power",
native_unit_of_measurement=UnitOfPower.WATT, native_unit_of_measurement=UnitOfPower.WATT,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.POWER, device_class=SensorDeviceClass.POWER,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
SensorEntityDescription( HiveSensorEntityDescription(
key="Current_Temperature", key="Current_Temperature",
native_unit_of_measurement=UnitOfTemperature.CELSIUS, native_unit_of_measurement=UnitOfTemperature.CELSIUS,
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
), ),
HiveSensorEntityDescription(
key="Heating_Current_Temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
HiveSensorEntityDescription(
key="Heating_Target_Temperature",
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
),
HiveSensorEntityDescription(
key="Heating_Mode",
device_class=SensorDeviceClass.ENUM,
options=["schedule", "on", "off"],
translation_key="heating",
fn=lambda x: x.lower() if isinstance(x, str) else None,
),
HiveSensorEntityDescription(
key="Hotwater_Mode",
device_class=SensorDeviceClass.ENUM,
options=["schedule", "on", "off"],
translation_key="hot_water",
fn=lambda x: x.lower() if isinstance(x, str) else None,
),
) )
@ -73,11 +110,13 @@ async def async_setup_entry(
class HiveSensorEntity(HiveEntity, SensorEntity): class HiveSensorEntity(HiveEntity, SensorEntity):
"""Hive Sensor Entity.""" """Hive Sensor Entity."""
entity_description: HiveSensorEntityDescription
def __init__( def __init__(
self, self,
hive: Hive, hive: Hive,
hive_device: dict[str, Any], hive_device: dict[str, Any],
entity_description: SensorEntityDescription, entity_description: HiveSensorEntityDescription,
) -> None: ) -> None:
"""Initialise hive sensor.""" """Initialise hive sensor."""
super().__init__(hive, hive_device) super().__init__(hive, hive_device)
@ -87,4 +126,6 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
"""Update all Node data from Hive.""" """Update all Node data from Hive."""
await self.hive.session.updateData(self.device) await self.hive.session.updateData(self.device)
self.device = await self.hive.sensor.getSensor(self.device) self.device = await self.hive.sensor.getSensor(self.device)
self._attr_native_value = self.device["status"]["state"] self._attr_native_value = self.entity_description.fn(
self.device["status"]["state"]
)

View File

@ -100,5 +100,23 @@
} }
} }
} }
},
"entity": {
"sensor": {
"heating": {
"state": {
"on": "[%key:common::state::on%]",
"off": "[%key:common::state::off%]",
"schedule": "Schedule"
}
},
"hot_water": {
"state": {
"on": "[%key:common::state::on%]",
"off": "[%key:common::state::off%]",
"schedule": "[%key:component::hive::entity::sensor::heating::state::schedule%]"
}
}
}
} }
} }