diff --git a/custom_components/prana/const.py b/custom_components/prana/const.py index 7af7b69..73300a9 100644 --- a/custom_components/prana/const.py +++ b/custom_components/prana/const.py @@ -2,11 +2,11 @@ # Common consts DOMAIN = "prana" -PLATFORMS = ("fan", "switch", "light") # MUST BE THE FIRST IN THE LIST +PLATFORMS = ("fan", "switch", "light", "sensor") # MUST BE THE FIRST IN THE LIST SIGNAL_PRANA_MAIN_INITIALIZED = "prana_main_initialized" -PRANA_DISCOVERY_TIMEOUT = 10 +PRANA_DISCOVERY_TIMEOUT = 16 class ConnectionType(Enum): @@ -48,6 +48,12 @@ class ConnectionType(Enum): ATTR_WINTER_MODE_ON = "winter_mode" ATTR_HEATING = "heating" ATTR_BRIGHTNESS = "brightness" +ATTR_SENSOR_TEMPERATURE_IN = "temperature_in" +ATTR_SENSOR_TEMPERATURE_OUT = "temperature_out" +ATTR_SENSOR_HUMIDITY = "humidity" +ATTR_SENSOR_PRESSURE = "pressure" +ATTR_SENSOR_VOC = "voc" +ATTR_SENSOR_CO2 = "co2" # Device attributes ATTR_DEVICE_ADDRESS = "ble_address" diff --git a/custom_components/prana/fan.py b/custom_components/prana/fan.py index 0cf2026..ab4348f 100644 --- a/custom_components/prana/fan.py +++ b/custom_components/prana/fan.py @@ -148,6 +148,12 @@ def state_attributes(self) -> dict: const.ATTR_FLOWS_LOCKED: state.flows_locked, const.ATTR_HEATING: state.mini_heating_enabled, const.ATTR_WINTER_MODE_ON: state.winter_mode_enabled, + const.ATTR_SENSOR_TEMPERATURE_IN: state.sensors.temperature_in, + const.ATTR_SENSOR_TEMPERATURE_OUT: state.sensors.temperature_out, + const.ATTR_SENSOR_HUMIDITY: state.sensors.humidity, + const.ATTR_SENSOR_PRESSURE: state.sensors.pressure, + const.ATTR_SENSOR_VOC: state.sensors.voc, + const.ATTR_SENSOR_CO2: state.sensors.co2, const.ATTR_IN_SPEED: in_speed, const.ATTR_OUT_SPEED: out_speed, } diff --git a/custom_components/prana/sensor.py b/custom_components/prana/sensor.py new file mode 100644 index 0000000..cf3e87a --- /dev/null +++ b/custom_components/prana/sensor.py @@ -0,0 +1,138 @@ +from typing import List, Optional + +from homeassistant.components.sensor import SensorEntity, SensorStateClass +from homeassistant.config_entries import ConfigEntry +from homeassistant.core import HomeAssistant + +from custom_components.prana import const +from custom_components.prana.entity import PranaDependantEntity + + +async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities, discovery_info=None): + entities: List[PranaDependantEntity] = [] + + for prana_fan in hass.data[const.DOMAIN][config_entry.entry_id][const.DATA_MAIN_ENTITIES]: + entities.append(PranaCO2(prana_fan)) + entities.append(PranaVOC(prana_fan)) + entities.append(PranaHumidity(prana_fan)) + entities.append(PranaAirPressure(prana_fan)) + entities.append(PranaAirTemperatureIn(prana_fan)) + entities.append(PranaAirTemperatureOut(prana_fan)) + + if len(entities) > 0: + async_add_entities(entities) + hass.data[const.DOMAIN][config_entry.entry_id][const.DATA_ENTITIES] += entities + + +class PranaCO2(PranaDependantEntity, SensorEntity): + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_icon = "mdi:molecule-co2" + + @property + def unique_id(self) -> Optional[str]: + return self.main_entity.unique_id + "_co2" + + @property + def name(self) -> Optional[str]: + return self.main_entity.name + " CO2" + + @property + def native_value(self): + prana_value = self.main_entity._prana_state.sensors.co2 + return prana_value + + +class PranaVOC(PranaDependantEntity, SensorEntity): + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_icon = "mdi:air-filter" + + @property + def unique_id(self) -> Optional[str]: + return self.main_entity.unique_id + "_voc" + + @property + def name(self) -> Optional[str]: + return self.main_entity.name + " VOC" + + @property + def native_value(self): + prana_value = self.main_entity._prana_state.sensors.voc + return prana_value + + +class PranaHumidity(PranaDependantEntity, SensorEntity): + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_icon = "mdi:water-percent" + + @property + def unique_id(self) -> Optional[str]: + return self.main_entity.unique_id + "_humidity" + + @property + def name(self) -> Optional[str]: + return self.main_entity.name + " Humidity" + + @property + def native_value(self): + prana_value = self.main_entity._prana_state.sensors.humidity + return prana_value + + +class PranaAirPressure(PranaDependantEntity, SensorEntity): + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_icon = "mdi:gauge" + + @property + def unique_id(self) -> Optional[str]: + return self.main_entity.unique_id + "_pressure" + + @property + def name(self) -> Optional[str]: + return self.main_entity.name + " Pressure" + + @property + def native_value(self): + prana_value = self.main_entity._prana_state.sensors.pressure + return prana_value + + +class PranaAirTemperatureIn(PranaDependantEntity, SensorEntity): + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_icon = "mdi:thermometer" + + @property + def unique_id(self) -> Optional[str]: + return self.main_entity.unique_id + "_temperature_in" + + @property + def name(self) -> Optional[str]: + return self.main_entity.name + " Temperature In" + + @property + def native_value(self): + prana_value = self.main_entity._prana_state.sensors.temperature_in + return prana_value + + +class PranaAirTemperatureOut(PranaDependantEntity, SensorEntity): + + _attr_state_class = SensorStateClass.MEASUREMENT + _attr_icon = "mdi:thermometer" + + @property + def unique_id(self) -> Optional[str]: + return self.main_entity.unique_id + "_temperature_out" + + @property + def name(self) -> Optional[str]: + return self.main_entity.name + " Temperature Out" + + @property + def native_value(self): + prana_value = self.main_entity._prana_state.sensors.temperature_out + return prana_value diff --git a/custom_components/prana/utils.py b/custom_components/prana/utils.py index 66dd247..bbaa856 100644 --- a/custom_components/prana/utils.py +++ b/custom_components/prana/utils.py @@ -7,7 +7,7 @@ from . import const -PRANA_SPEEDS = ["Off", "Low", "2", "3", "4", "5", "6", "7", "8", "High"] +PRANA_SPEEDS = ["Off", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"] PRANA_DEFAULT_SPEED = "2"