2019-06-06 22:23:00 +00:00
|
|
|
"""Support for Salda Smarty XP/XV Ventilation Unit Sensors."""
|
|
|
|
|
|
|
|
import datetime as dt
|
|
|
|
import logging
|
|
|
|
|
2021-03-22 18:54:14 +00:00
|
|
|
from homeassistant.components.sensor import SensorEntity
|
2019-06-06 22:23:00 +00:00
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
DEVICE_CLASS_TIMESTAMP,
|
2019-12-01 05:24:17 +00:00
|
|
|
TEMP_CELSIUS,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-12-01 05:24:17 +00:00
|
|
|
from homeassistant.core import callback
|
2019-06-06 22:23:00 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2019-12-01 05:24:17 +00:00
|
|
|
import homeassistant.util.dt as dt_util
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
from . import DOMAIN, SIGNAL_UPDATE_SMARTY
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2019-06-06 22:23:00 +00:00
|
|
|
"""Set up the Smarty Sensor Platform."""
|
2019-07-31 19:25:30 +00:00
|
|
|
smarty = hass.data[DOMAIN]["api"]
|
|
|
|
name = hass.data[DOMAIN]["name"]
|
|
|
|
|
|
|
|
sensors = [
|
|
|
|
SupplyAirTemperatureSensor(name, smarty),
|
|
|
|
ExtractAirTemperatureSensor(name, smarty),
|
|
|
|
OutdoorAirTemperatureSensor(name, smarty),
|
|
|
|
SupplyFanSpeedSensor(name, smarty),
|
|
|
|
ExtractFanSpeedSensor(name, smarty),
|
|
|
|
FilterDaysLeftSensor(name, smarty),
|
|
|
|
]
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
async_add_entities(sensors, True)
|
|
|
|
|
|
|
|
|
2021-03-22 18:54:14 +00:00
|
|
|
class SmartySensor(SensorEntity):
|
2019-06-06 22:23:00 +00:00
|
|
|
"""Representation of a Smarty Sensor."""
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def __init__(
|
|
|
|
self, name: str, device_class: str, smarty, unit_of_measurement: str = ""
|
|
|
|
):
|
2019-06-06 22:23:00 +00:00
|
|
|
"""Initialize the entity."""
|
|
|
|
self._name = name
|
|
|
|
self._state = None
|
|
|
|
self._sensor_type = device_class
|
|
|
|
self._unit_of_measurement = unit_of_measurement
|
|
|
|
self._smarty = smarty
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self) -> bool:
|
|
|
|
"""Do not poll."""
|
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return self._sensor_type
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
async def async_added_to_hass(self):
|
|
|
|
"""Call to update."""
|
2019-07-31 19:25:30 +00:00
|
|
|
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
@callback
|
|
|
|
def _update_callback(self):
|
|
|
|
"""Call update method."""
|
|
|
|
self.async_schedule_update_ha_state(True)
|
|
|
|
|
|
|
|
|
|
|
|
class SupplyAirTemperatureSensor(SmartySensor):
|
|
|
|
"""Supply Air Temperature Sensor."""
|
|
|
|
|
|
|
|
def __init__(self, name, smarty):
|
|
|
|
"""Supply Air Temperature Init."""
|
2019-07-31 19:25:30 +00:00
|
|
|
super().__init__(
|
2019-09-03 19:14:39 +00:00
|
|
|
name=f"{name} Supply Air Temperature",
|
2019-07-31 19:25:30 +00:00
|
|
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
|
|
|
unit_of_measurement=TEMP_CELSIUS,
|
|
|
|
smarty=smarty,
|
|
|
|
)
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
def update(self) -> None:
|
|
|
|
"""Update state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Updating sensor %s", self._name)
|
2019-06-06 22:23:00 +00:00
|
|
|
self._state = self._smarty.supply_air_temperature
|
|
|
|
|
|
|
|
|
|
|
|
class ExtractAirTemperatureSensor(SmartySensor):
|
|
|
|
"""Extract Air Temperature Sensor."""
|
|
|
|
|
|
|
|
def __init__(self, name, smarty):
|
|
|
|
"""Supply Air Temperature Init."""
|
2019-07-31 19:25:30 +00:00
|
|
|
super().__init__(
|
2019-09-03 19:14:39 +00:00
|
|
|
name=f"{name} Extract Air Temperature",
|
2019-07-31 19:25:30 +00:00
|
|
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
|
|
|
unit_of_measurement=TEMP_CELSIUS,
|
|
|
|
smarty=smarty,
|
|
|
|
)
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
def update(self) -> None:
|
|
|
|
"""Update state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Updating sensor %s", self._name)
|
2019-06-06 22:23:00 +00:00
|
|
|
self._state = self._smarty.extract_air_temperature
|
|
|
|
|
|
|
|
|
|
|
|
class OutdoorAirTemperatureSensor(SmartySensor):
|
|
|
|
"""Extract Air Temperature Sensor."""
|
|
|
|
|
|
|
|
def __init__(self, name, smarty):
|
|
|
|
"""Outdoor Air Temperature Init."""
|
2019-07-31 19:25:30 +00:00
|
|
|
super().__init__(
|
2019-09-03 19:14:39 +00:00
|
|
|
name=f"{name} Outdoor Air Temperature",
|
2019-07-31 19:25:30 +00:00
|
|
|
device_class=DEVICE_CLASS_TEMPERATURE,
|
|
|
|
unit_of_measurement=TEMP_CELSIUS,
|
|
|
|
smarty=smarty,
|
|
|
|
)
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
def update(self) -> None:
|
|
|
|
"""Update state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Updating sensor %s", self._name)
|
2019-06-06 22:23:00 +00:00
|
|
|
self._state = self._smarty.outdoor_air_temperature
|
|
|
|
|
|
|
|
|
|
|
|
class SupplyFanSpeedSensor(SmartySensor):
|
|
|
|
"""Supply Fan Speed RPM."""
|
|
|
|
|
|
|
|
def __init__(self, name, smarty):
|
|
|
|
"""Supply Fan Speed RPM Init."""
|
2019-07-31 19:25:30 +00:00
|
|
|
super().__init__(
|
2019-09-03 19:14:39 +00:00
|
|
|
name=f"{name} Supply Fan Speed",
|
2019-07-31 19:25:30 +00:00
|
|
|
device_class=None,
|
|
|
|
unit_of_measurement=None,
|
|
|
|
smarty=smarty,
|
|
|
|
)
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
def update(self) -> None:
|
|
|
|
"""Update state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Updating sensor %s", self._name)
|
2019-06-06 22:23:00 +00:00
|
|
|
self._state = self._smarty.supply_fan_speed
|
|
|
|
|
|
|
|
|
|
|
|
class ExtractFanSpeedSensor(SmartySensor):
|
|
|
|
"""Extract Fan Speed RPM."""
|
|
|
|
|
|
|
|
def __init__(self, name, smarty):
|
|
|
|
"""Extract Fan Speed RPM Init."""
|
2019-07-31 19:25:30 +00:00
|
|
|
super().__init__(
|
2019-09-03 19:14:39 +00:00
|
|
|
name=f"{name} Extract Fan Speed",
|
2019-07-31 19:25:30 +00:00
|
|
|
device_class=None,
|
|
|
|
unit_of_measurement=None,
|
|
|
|
smarty=smarty,
|
|
|
|
)
|
2019-06-06 22:23:00 +00:00
|
|
|
|
|
|
|
def update(self) -> None:
|
|
|
|
"""Update state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Updating sensor %s", self._name)
|
2019-06-06 22:23:00 +00:00
|
|
|
self._state = self._smarty.extract_fan_speed
|
|
|
|
|
|
|
|
|
|
|
|
class FilterDaysLeftSensor(SmartySensor):
|
|
|
|
"""Filter Days Left."""
|
|
|
|
|
|
|
|
def __init__(self, name, smarty):
|
|
|
|
"""Filter Days Left Init."""
|
2019-07-31 19:25:30 +00:00
|
|
|
super().__init__(
|
2019-09-03 19:14:39 +00:00
|
|
|
name=f"{name} Filter Days Left",
|
2019-07-31 19:25:30 +00:00
|
|
|
device_class=DEVICE_CLASS_TIMESTAMP,
|
|
|
|
unit_of_measurement=None,
|
|
|
|
smarty=smarty,
|
|
|
|
)
|
2019-06-06 22:23:00 +00:00
|
|
|
self._days_left = 91
|
|
|
|
|
|
|
|
def update(self) -> None:
|
|
|
|
"""Update state."""
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Updating sensor %s", self._name)
|
2019-06-06 22:23:00 +00:00
|
|
|
days_left = self._smarty.filter_timer
|
|
|
|
if days_left is not None and days_left != self._days_left:
|
|
|
|
self._state = dt_util.now() + dt.timedelta(days=days_left)
|
|
|
|
self._days_left = days_left
|