2019-04-03 15:40:03 +00:00
|
|
|
"""Support for Waterfurnace."""
|
2018-01-20 21:51:59 +00:00
|
|
|
|
2021-03-22 18:50:29 +00:00
|
|
|
from homeassistant.components.sensor import ENTITY_ID_FORMAT, SensorEntity
|
2021-07-13 12:20:47 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
|
|
|
PERCENTAGE,
|
|
|
|
POWER_WATT,
|
|
|
|
TEMP_FAHRENHEIT,
|
|
|
|
)
|
2018-01-20 21:51:59 +00:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.util import slugify
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as WF_DOMAIN, UPDATE_TOPIC
|
|
|
|
|
2018-01-20 21:51:59 +00:00
|
|
|
|
2018-07-20 08:45:20 +00:00
|
|
|
class WFSensorConfig:
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Water Furnace Sensor configuration."""
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
def __init__(
|
2021-07-13 12:20:47 +00:00
|
|
|
self,
|
|
|
|
friendly_name,
|
|
|
|
field,
|
|
|
|
icon="mdi:gauge",
|
|
|
|
unit_of_measurement=None,
|
|
|
|
device_class=None,
|
2019-07-31 19:25:30 +00:00
|
|
|
):
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Initialize configuration."""
|
2021-07-13 12:20:47 +00:00
|
|
|
self.device_class = device_class
|
2018-01-20 21:51:59 +00:00
|
|
|
self.friendly_name = friendly_name
|
|
|
|
self.field = field
|
|
|
|
self.icon = icon
|
|
|
|
self.unit_of_measurement = unit_of_measurement
|
|
|
|
|
|
|
|
|
|
|
|
SENSORS = [
|
|
|
|
WFSensorConfig("Furnace Mode", "mode"),
|
2020-04-11 13:40:59 +00:00
|
|
|
WFSensorConfig("Total Power", "totalunitpower", "mdi:flash", POWER_WATT),
|
2019-07-31 19:25:30 +00:00
|
|
|
WFSensorConfig(
|
2021-07-13 12:20:47 +00:00
|
|
|
"Active Setpoint",
|
|
|
|
"tstatactivesetpoint",
|
|
|
|
None,
|
|
|
|
TEMP_FAHRENHEIT,
|
|
|
|
DEVICE_CLASS_TEMPERATURE,
|
2019-07-31 19:25:30 +00:00
|
|
|
),
|
|
|
|
WFSensorConfig(
|
2021-07-13 12:20:47 +00:00
|
|
|
"Leaving Air", "leavingairtemp", None, TEMP_FAHRENHEIT, DEVICE_CLASS_TEMPERATURE
|
2019-07-31 19:25:30 +00:00
|
|
|
),
|
2021-07-13 12:20:47 +00:00
|
|
|
WFSensorConfig(
|
|
|
|
"Room Temp", "tstatroomtemp", None, TEMP_FAHRENHEIT, DEVICE_CLASS_TEMPERATURE
|
|
|
|
),
|
|
|
|
WFSensorConfig("Loop Temp", "enteringwatertemp", None, TEMP_FAHRENHEIT),
|
2019-07-31 19:25:30 +00:00
|
|
|
WFSensorConfig(
|
2020-09-05 19:09:14 +00:00
|
|
|
"Humidity Set Point", "tstathumidsetpoint", "mdi:water-percent", PERCENTAGE
|
2020-02-28 19:46:48 +00:00
|
|
|
),
|
|
|
|
WFSensorConfig(
|
2020-09-05 19:09:14 +00:00
|
|
|
"Humidity", "tstatrelativehumidity", "mdi:water-percent", PERCENTAGE
|
2019-07-31 19:25:30 +00:00
|
|
|
),
|
2020-04-11 13:40:59 +00:00
|
|
|
WFSensorConfig("Compressor Power", "compressorpower", "mdi:flash", POWER_WATT),
|
|
|
|
WFSensorConfig("Fan Power", "fanpower", "mdi:flash", POWER_WATT),
|
|
|
|
WFSensorConfig("Aux Power", "auxpower", "mdi:flash", POWER_WATT),
|
|
|
|
WFSensorConfig("Loop Pump Power", "looppumppower", "mdi:flash", POWER_WATT),
|
2019-07-31 19:25:30 +00:00
|
|
|
WFSensorConfig("Compressor Speed", "actualcompressorspeed", "mdi:speedometer"),
|
2018-11-29 11:04:12 +00:00
|
|
|
WFSensorConfig("Fan Speed", "airflowcurrentspeed", "mdi:fan"),
|
2018-01-20 21:51:59 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Set up the Waterfurnace sensor."""
|
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
sensors = []
|
|
|
|
client = hass.data[WF_DOMAIN]
|
|
|
|
for sconfig in SENSORS:
|
|
|
|
sensors.append(WaterFurnaceSensor(client, sconfig))
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(sensors)
|
2018-01-20 21:51:59 +00:00
|
|
|
|
|
|
|
|
2021-03-22 18:50:29 +00:00
|
|
|
class WaterFurnaceSensor(SensorEntity):
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Implementing the Waterfurnace sensor."""
|
|
|
|
|
|
|
|
def __init__(self, client, config):
|
|
|
|
"""Initialize the sensor."""
|
|
|
|
self.client = client
|
|
|
|
self._name = config.friendly_name
|
|
|
|
self._attr = config.field
|
|
|
|
self._state = None
|
|
|
|
self._icon = config.icon
|
|
|
|
self._unit_of_measurement = config.unit_of_measurement
|
2021-07-13 12:20:47 +00:00
|
|
|
self._attr_device_class = config.device_class
|
2018-01-20 21:51:59 +00:00
|
|
|
|
|
|
|
# This ensures that the sensors are isolated per waterfurnace unit
|
|
|
|
self.entity_id = ENTITY_ID_FORMAT.format(
|
2021-04-09 16:58:27 +00:00
|
|
|
f"wf_{slugify(self.client.unit)}_{slugify(self._attr)}"
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-01-20 21:51:59 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
2021-08-11 19:17:16 +00:00
|
|
|
def native_value(self):
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self._state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return icon."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
2021-08-11 19:17:16 +00:00
|
|
|
def native_unit_of_measurement(self):
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Return the units of measurement."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
"""Return the polling state."""
|
|
|
|
return False
|
|
|
|
|
2018-10-01 06:55:43 +00:00
|
|
|
async def async_added_to_hass(self):
|
2018-01-20 21:51:59 +00:00
|
|
|
"""Register callbacks."""
|
2020-04-02 16:25:33 +00:00
|
|
|
self.async_on_remove(
|
|
|
|
self.hass.helpers.dispatcher.async_dispatcher_connect(
|
|
|
|
UPDATE_TOPIC, self.async_update_callback
|
|
|
|
)
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2018-01-20 21:51:59 +00:00
|
|
|
|
|
|
|
@callback
|
|
|
|
def async_update_callback(self):
|
|
|
|
"""Update state."""
|
|
|
|
if self.client.data is not None:
|
|
|
|
self._state = getattr(self.client.data, self._attr, None)
|
2020-04-01 21:19:51 +00:00
|
|
|
self.async_write_ha_state()
|