2019-02-15 13:54:25 +00:00
|
|
|
"""Support for the for Danfoss Air HRV sensors."""
|
2022-01-03 18:16:42 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2019-02-15 13:54:25 +00:00
|
|
|
import logging
|
2019-01-23 16:58:45 +00:00
|
|
|
|
2020-04-04 13:41:33 +00:00
|
|
|
from pydanfossair.commands import ReadCommand
|
|
|
|
|
2021-12-13 23:17:08 +00:00
|
|
|
from homeassistant.components.sensor import (
|
|
|
|
SensorDeviceClass,
|
|
|
|
SensorEntity,
|
|
|
|
SensorStateClass,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2022-12-20 16:59:20 +00:00
|
|
|
from homeassistant.const import PERCENTAGE, REVOLUTIONS_PER_MINUTE, UnitOfTemperature
|
2022-01-03 18:16:42 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2019-01-23 16:58:45 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as DANFOSS_AIR_DOMAIN
|
|
|
|
|
2019-02-15 13:54:25 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-01-23 16:58:45 +00:00
|
|
|
|
2022-01-03 18:16:42 +00:00
|
|
|
def setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2019-01-23 16:58:45 +00:00
|
|
|
"""Set up the available Danfoss Air sensors etc."""
|
|
|
|
data = hass.data[DANFOSS_AIR_DOMAIN]
|
|
|
|
|
|
|
|
sensors = [
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
|
|
|
"Danfoss Air Exhaust Temperature",
|
2022-12-20 16:59:20 +00:00
|
|
|
UnitOfTemperature.CELSIUS,
|
2019-07-31 19:25:30 +00:00
|
|
|
ReadCommand.exhaustTemperature,
|
2021-12-13 23:17:08 +00:00
|
|
|
SensorDeviceClass.TEMPERATURE,
|
|
|
|
SensorStateClass.MEASUREMENT,
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Outdoor Temperature",
|
2022-12-20 16:59:20 +00:00
|
|
|
UnitOfTemperature.CELSIUS,
|
2019-07-31 19:25:30 +00:00
|
|
|
ReadCommand.outdoorTemperature,
|
2021-12-13 23:17:08 +00:00
|
|
|
SensorDeviceClass.TEMPERATURE,
|
|
|
|
SensorStateClass.MEASUREMENT,
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Supply Temperature",
|
2022-12-20 16:59:20 +00:00
|
|
|
UnitOfTemperature.CELSIUS,
|
2019-07-31 19:25:30 +00:00
|
|
|
ReadCommand.supplyTemperature,
|
2021-12-13 23:17:08 +00:00
|
|
|
SensorDeviceClass.TEMPERATURE,
|
|
|
|
SensorStateClass.MEASUREMENT,
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Extract Temperature",
|
2022-12-20 16:59:20 +00:00
|
|
|
UnitOfTemperature.CELSIUS,
|
2019-07-31 19:25:30 +00:00
|
|
|
ReadCommand.extractTemperature,
|
2021-12-13 23:17:08 +00:00
|
|
|
SensorDeviceClass.TEMPERATURE,
|
|
|
|
SensorStateClass.MEASUREMENT,
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
2020-02-28 19:46:48 +00:00
|
|
|
[
|
|
|
|
"Danfoss Air Remaining Filter",
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2020-02-28 19:46:48 +00:00
|
|
|
ReadCommand.filterPercent,
|
|
|
|
None,
|
2021-08-22 17:59:59 +00:00
|
|
|
None,
|
2020-02-28 19:46:48 +00:00
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Humidity",
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2020-02-28 19:46:48 +00:00
|
|
|
ReadCommand.humidity,
|
2021-12-13 23:17:08 +00:00
|
|
|
SensorDeviceClass.HUMIDITY,
|
|
|
|
SensorStateClass.MEASUREMENT,
|
2021-08-22 17:59:59 +00:00
|
|
|
],
|
|
|
|
["Danfoss Air Fan Step", PERCENTAGE, ReadCommand.fan_step, None, None],
|
|
|
|
[
|
|
|
|
"Danfoss Air Exhaust Fan Speed",
|
2022-10-11 12:56:10 +00:00
|
|
|
REVOLUTIONS_PER_MINUTE,
|
2021-08-22 17:59:59 +00:00
|
|
|
ReadCommand.exhaust_fan_speed,
|
|
|
|
None,
|
|
|
|
None,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Supply Fan Speed",
|
2022-10-11 12:56:10 +00:00
|
|
|
REVOLUTIONS_PER_MINUTE,
|
2021-08-22 17:59:59 +00:00
|
|
|
ReadCommand.supply_fan_speed,
|
|
|
|
None,
|
|
|
|
None,
|
2020-02-28 19:46:48 +00:00
|
|
|
],
|
2019-07-31 19:25:30 +00:00
|
|
|
[
|
2020-02-03 20:31:53 +00:00
|
|
|
"Danfoss Air Dial Battery",
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2019-07-31 19:25:30 +00:00
|
|
|
ReadCommand.battery_percent,
|
2021-12-13 23:17:08 +00:00
|
|
|
SensorDeviceClass.BATTERY,
|
2021-08-22 17:59:59 +00:00
|
|
|
None,
|
2019-07-31 19:25:30 +00:00
|
|
|
],
|
|
|
|
]
|
2019-01-23 16:58:45 +00:00
|
|
|
|
|
|
|
dev = []
|
|
|
|
|
|
|
|
for sensor in sensors:
|
2021-08-22 17:59:59 +00:00
|
|
|
dev.append(
|
|
|
|
DanfossAir(data, sensor[0], sensor[1], sensor[2], sensor[3], sensor[4])
|
|
|
|
)
|
2019-01-23 16:58:45 +00:00
|
|
|
|
2019-01-26 14:55:25 +00:00
|
|
|
add_entities(dev, True)
|
2019-01-23 16:58:45 +00:00
|
|
|
|
|
|
|
|
2021-03-22 11:52:29 +00:00
|
|
|
class DanfossAir(SensorEntity):
|
2019-01-23 16:58:45 +00:00
|
|
|
"""Representation of a Sensor."""
|
|
|
|
|
2021-08-22 17:59:59 +00:00
|
|
|
def __init__(self, data, name, sensor_unit, sensor_type, device_class, state_class):
|
2019-01-23 16:58:45 +00:00
|
|
|
"""Initialize the sensor."""
|
|
|
|
self._data = data
|
2021-12-13 23:17:08 +00:00
|
|
|
self._attr_name = name
|
|
|
|
self._attr_native_value = None
|
2019-01-26 14:55:25 +00:00
|
|
|
self._type = sensor_type
|
2021-12-13 23:17:08 +00:00
|
|
|
self._attr_native_unit_of_measurement = sensor_unit
|
|
|
|
self._attr_device_class = device_class
|
2021-08-22 17:59:59 +00:00
|
|
|
self._attr_state_class = state_class
|
2019-01-23 16:58:45 +00:00
|
|
|
|
2022-08-19 14:10:45 +00:00
|
|
|
def update(self) -> None:
|
2019-01-23 16:58:45 +00:00
|
|
|
"""Update the new state of the sensor.
|
|
|
|
|
2019-01-26 14:55:25 +00:00
|
|
|
This is done through the DanfossAir object that does the actual
|
2019-01-23 16:58:45 +00:00
|
|
|
communication with the Air CCM.
|
|
|
|
"""
|
|
|
|
self._data.update()
|
|
|
|
|
2021-12-13 23:17:08 +00:00
|
|
|
self._attr_native_value = self._data.get_value(self._type)
|
|
|
|
if self._attr_native_value is None:
|
2019-02-15 13:54:25 +00:00
|
|
|
_LOGGER.debug("Could not get data for %s", self._type)
|