2019-02-15 13:54:25 +00:00
|
|
|
"""Support for the for Danfoss Air HRV sensors."""
|
|
|
|
import logging
|
2019-01-23 16:58:45 +00:00
|
|
|
|
2020-04-04 13:41:33 +00:00
|
|
|
from pydanfossair.commands import ReadCommand
|
|
|
|
|
2019-02-15 13:54:25 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
DEVICE_CLASS_BATTERY,
|
|
|
|
DEVICE_CLASS_HUMIDITY,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2019-07-31 19:25:30 +00:00
|
|
|
TEMP_CELSIUS,
|
|
|
|
)
|
2019-01-23 16:58:45 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
|
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
|
|
|
|
2019-01-26 14:55:25 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=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",
|
|
|
|
TEMP_CELSIUS,
|
|
|
|
ReadCommand.exhaustTemperature,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Outdoor Temperature",
|
|
|
|
TEMP_CELSIUS,
|
|
|
|
ReadCommand.outdoorTemperature,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Supply Temperature",
|
|
|
|
TEMP_CELSIUS,
|
|
|
|
ReadCommand.supplyTemperature,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Extract Temperature",
|
|
|
|
TEMP_CELSIUS,
|
|
|
|
ReadCommand.extractTemperature,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
],
|
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,
|
|
|
|
],
|
|
|
|
[
|
|
|
|
"Danfoss Air Humidity",
|
2020-09-05 19:09:14 +00:00
|
|
|
PERCENTAGE,
|
2020-02-28 19:46:48 +00:00
|
|
|
ReadCommand.humidity,
|
|
|
|
DEVICE_CLASS_HUMIDITY,
|
|
|
|
],
|
2020-09-05 19:09:14 +00:00
|
|
|
["Danfoss Air Fan Step", PERCENTAGE, ReadCommand.fan_step, None],
|
2020-02-03 20:31:53 +00:00
|
|
|
["Danfoss Air Exhaust Fan Speed", "RPM", ReadCommand.exhaust_fan_speed, None],
|
|
|
|
["Danfoss Air Supply Fan Speed", "RPM", ReadCommand.supply_fan_speed, None],
|
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,
|
|
|
|
DEVICE_CLASS_BATTERY,
|
|
|
|
],
|
|
|
|
]
|
2019-01-23 16:58:45 +00:00
|
|
|
|
|
|
|
dev = []
|
|
|
|
|
|
|
|
for sensor in sensors:
|
2019-07-31 19:25:30 +00:00
|
|
|
dev.append(DanfossAir(data, sensor[0], sensor[1], sensor[2], sensor[3]))
|
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
|
|
|
|
|
|
|
|
|
|
|
class DanfossAir(Entity):
|
|
|
|
"""Representation of a Sensor."""
|
|
|
|
|
2019-02-15 13:54:25 +00:00
|
|
|
def __init__(self, data, name, sensor_unit, sensor_type, device_class):
|
2019-01-23 16:58:45 +00:00
|
|
|
"""Initialize the sensor."""
|
|
|
|
self._data = data
|
|
|
|
self._name = name
|
|
|
|
self._state = None
|
2019-01-26 14:55:25 +00:00
|
|
|
self._type = sensor_type
|
|
|
|
self._unit = sensor_unit
|
2019-02-15 13:54:25 +00:00
|
|
|
self._device_class = device_class
|
2019-01-23 16:58:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
2019-02-15 13:54:25 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return self._device_class
|
|
|
|
|
2019-01-23 16:58:45 +00:00
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit of measurement."""
|
|
|
|
return self._unit
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""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()
|
|
|
|
|
|
|
|
self._state = self._data.get_value(self._type)
|
2019-02-15 13:54:25 +00:00
|
|
|
if self._state is None:
|
|
|
|
_LOGGER.debug("Could not get data for %s", self._type)
|