From a966c7dc3810898420d1c7d67d763ab06e2d64d8 Mon Sep 17 00:00:00 2001 From: Sergiu Popescu Date: Mon, 28 Mar 2022 18:48:21 +0300 Subject: [PATCH 1/5] Add sensors data --- custom_components/prana/fan.py | 6 ++++++ 1 file changed, 6 insertions(+) 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, } From e769cb36d85736119f6b20f86cfcec54702fab95 Mon Sep 17 00:00:00 2001 From: Sergiu Popescu Date: Mon, 28 Mar 2022 18:49:58 +0300 Subject: [PATCH 2/5] Add sensors const --- custom_components/prana/const.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/custom_components/prana/const.py b/custom_components/prana/const.py index 7af7b69..bdbeff0 100644 --- a/custom_components/prana/const.py +++ b/custom_components/prana/const.py @@ -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" From fad43a5c892e7b413cb710d3a1de21c4a352809f Mon Sep 17 00:00:00 2001 From: "sergiu.popescu" Date: Mon, 28 Mar 2022 21:45:44 +0300 Subject: [PATCH 3/5] Add CO2 sensor --- custom_components/prana/const.py | 14 +++++------ custom_components/prana/fan.py | 10 ++++---- custom_components/prana/sensor.py | 39 +++++++++++++++++++++++++++++++ custom_components/prana/utils.py | 2 +- 4 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 custom_components/prana/sensor.py diff --git a/custom_components/prana/const.py b/custom_components/prana/const.py index bdbeff0..f325f48 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,11 +48,11 @@ 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_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 diff --git a/custom_components/prana/fan.py b/custom_components/prana/fan.py index ab4348f..2ad645f 100644 --- a/custom_components/prana/fan.py +++ b/custom_components/prana/fan.py @@ -148,11 +148,11 @@ 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_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..a0f7f5a --- /dev/null +++ b/custom_components/prana/sensor.py @@ -0,0 +1,39 @@ +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)) + + 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): + """Return the brightness of this light between 0..255.""" + prana_value = self.main_entity._prana_state.sensors.co2 + 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" From 1fa0093f694f029502220ec00f5a079dc7b58e7e Mon Sep 17 00:00:00 2001 From: "sergiu.popescu" Date: Mon, 28 Mar 2022 22:00:32 +0300 Subject: [PATCH 4/5] Add all the sensors --- custom_components/prana/const.py | 10 +-- custom_components/prana/fan.py | 10 +-- custom_components/prana/sensor.py | 101 +++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 11 deletions(-) diff --git a/custom_components/prana/const.py b/custom_components/prana/const.py index f325f48..73300a9 100644 --- a/custom_components/prana/const.py +++ b/custom_components/prana/const.py @@ -48,11 +48,11 @@ 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_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 diff --git a/custom_components/prana/fan.py b/custom_components/prana/fan.py index 2ad645f..ab4348f 100644 --- a/custom_components/prana/fan.py +++ b/custom_components/prana/fan.py @@ -148,11 +148,11 @@ 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_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 index a0f7f5a..fb0d0bb 100644 --- a/custom_components/prana/sensor.py +++ b/custom_components/prana/sensor.py @@ -13,6 +13,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn 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) @@ -34,6 +39,100 @@ def name(self) -> Optional[str]: @property def native_value(self): - """Return the brightness of this light between 0..255.""" 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 Out" + + @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 From 3b0aec3680c0b60ff8709a244acb9ce7c7a0c51a Mon Sep 17 00:00:00 2001 From: "sergiu.popescu" Date: Mon, 28 Mar 2022 22:02:20 +0300 Subject: [PATCH 5/5] Fix Sensor Name --- custom_components/prana/sensor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/prana/sensor.py b/custom_components/prana/sensor.py index fb0d0bb..cf3e87a 100644 --- a/custom_components/prana/sensor.py +++ b/custom_components/prana/sensor.py @@ -111,7 +111,7 @@ def unique_id(self) -> Optional[str]: @property def name(self) -> Optional[str]: - return self.main_entity.name + " Temperature Out" + return self.main_entity.name + " Temperature In" @property def native_value(self):