mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
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:
parent
6bdc5be433
commit
1b7fb9ae12
@ -6,9 +6,14 @@
|
||||
},
|
||||
"hot_water": {
|
||||
"default": "mdi:hand-water"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"heating": {
|
||||
"default": "mdi:radiator"
|
||||
},
|
||||
"temperature": {
|
||||
"default": "mdi:thermometer"
|
||||
"hot_water": {
|
||||
"default": "mdi:hand-water"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1,5 +1,7 @@
|
||||
"""Support for the Hive sensors."""
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import timedelta
|
||||
from typing import Any
|
||||
|
||||
@ -20,6 +22,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
||||
from . import HiveEntity
|
||||
from .const import DOMAIN
|
||||
@ -27,27 +30,61 @@ from .const import DOMAIN
|
||||
PARALLEL_UPDATES = 0
|
||||
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",
|
||||
native_unit_of_measurement=PERCENTAGE,
|
||||
device_class=SensorDeviceClass.BATTERY,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HiveSensorEntityDescription(
|
||||
key="Power",
|
||||
native_unit_of_measurement=UnitOfPower.WATT,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.POWER,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
HiveSensorEntityDescription(
|
||||
key="Current_Temperature",
|
||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
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):
|
||||
"""Hive Sensor Entity."""
|
||||
|
||||
entity_description: HiveSensorEntityDescription
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
hive: Hive,
|
||||
hive_device: dict[str, Any],
|
||||
entity_description: SensorEntityDescription,
|
||||
entity_description: HiveSensorEntityDescription,
|
||||
) -> None:
|
||||
"""Initialise hive sensor."""
|
||||
super().__init__(hive, hive_device)
|
||||
@ -87,4 +126,6 @@ class HiveSensorEntity(HiveEntity, SensorEntity):
|
||||
"""Update all Node data from Hive."""
|
||||
await self.hive.session.updateData(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"]
|
||||
)
|
||||
|
@ -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%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user