From fda5208b32c38dcdcfc83d8da8570cf68f91f928 Mon Sep 17 00:00:00 2001 From: Oleh Date: Sat, 2 Oct 2021 22:54:02 +0300 Subject: [PATCH] new sensors added for energy consumption --- README.md | 11 ++- custom_components/ariston/ariston.py | 61 ++++++++++++- custom_components/ariston/const.py | 3 + custom_components/ariston/sensor.py | 130 ++++++++++++++++++--------- 4 files changed, 157 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index a18b2d0..debe582 100644 --- a/README.md +++ b/README.md @@ -79,10 +79,11 @@ Order of Installation: - `ch_set_temperature` - set CH temperature. - `ch_program` - CH Time Program. - `ch_water_temperature` - CH Water Temperature. **WORKS ONLY ON SPECIFIC MODELS WHILE ON OTHERS CAUSES CRASHES** - - `cooling_last_24h` - energy use for pump cooling in a day. - - `cooling_last_7d` - energy use for pump cooling in a week. - - `cooling_last_30d` - energy use for pump cooling in a month. - - `cooling_last_365d` - energy use for pump cooling in a year. + - `cooling_last_24h` - energy use for pump cooling in a day. Not supported on all models. + - `cooling_last_7d` - energy use for pump cooling in a week. Not supported on all models. + - `cooling_last_30d` - energy use for pump cooling in a month. Not supported on all models. + - `cooling_last_365d` - energy use for pump cooling in a year. Not supported on all models. + - `cooling_today` - energy use for pump cooling today. Not supported on all models. - `dhw_program` - DHW Time Program. - `dhw_comfort_function` - DHW comfort function. - `dhw_mode` - mode of DHW. Not supported on all models. @@ -99,6 +100,7 @@ Order of Installation: - `heating_last_30d` - energy use for heating in last 7 days. Not supported on all models. - `heating_last_365d` - energy use for heating in last 30 days. Not supported on all models. - `heating_last_7d` - energy use for heating in last 365 days. Not supported on all models. + - `heating_today` - energy use for heating today. Not supported on all models. - `mode` - mode of boiler (`off` or `summer` or `winter` and others). - `outside_temperature` - outside temperature. Not supported on all models. - `signal_strength` - Wifi signal strength. @@ -107,6 +109,7 @@ Order of Installation: - `water_last_30d` - energy use for water in last 7 days. Not supported on all models. - `water_last_365d` - energy use for water in last 30 days. Not supported on all models. - `water_last_7d` - energy use for water in last 365 days. Not supported on all models. + - `water_today` - energy use for water today. Not supported on all models. #### Binary sensors **Some parameters are not supported on all models** diff --git a/custom_components/ariston/ariston.py b/custom_components/ariston/ariston.py index 4ae3f52..9a36376 100644 --- a/custom_components/ariston/ariston.py +++ b/custom_components/ariston/ariston.py @@ -112,7 +112,7 @@ class AristonHandler: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ """ - _VERSION = "1.0.41" + _VERSION = "1.0.43" _LOGGER = logging.getLogger(__name__) _LEVEL_CRITICAL = "CRITICAL" @@ -151,6 +151,7 @@ class AristonHandler: _PARAM_COOLING_LAST_7D_LIST = "cooling_last_7d_list" _PARAM_COOLING_LAST_30D_LIST = "cooling_last_30d_list" _PARAM_COOLING_LAST_365D_LIST = "cooling_last_365d_list" + _PARAM_COOLING_TODAY = "cooling_today" _PARAM_ERRORS = "errors" _PARAM_ERRORS_COUNT = "errors_count" _PARAM_DHW_COMFORT_FUNCTION = "dhw_comfort_function" @@ -168,6 +169,7 @@ class AristonHandler: _PARAM_HEATING_LAST_7D_LIST = "heating_last_7d_list" _PARAM_HEATING_LAST_30D_LIST = "heating_last_30d_list" _PARAM_HEATING_LAST_365D_LIST = "heating_last_365d_list" + _PARAM_HEATING_TODAY = "heating_today" _PARAM_MODE = "mode" _PARAM_OUTSIDE_TEMPERATURE = "outside_temperature" _PARAM_SIGNAL_STRENGTH = "signal_strength" @@ -179,6 +181,7 @@ class AristonHandler: _PARAM_WATER_LAST_7D_LIST = "water_last_7d_list" _PARAM_WATER_LAST_30D_LIST = "water_last_30d_list" _PARAM_WATER_LAST_365D_LIST = "water_last_365d_list" + _PARAM_WATER_TODAY = "water_today" _PARAM_UNITS = "units" _PARAM_THERMAL_CLEANSE_CYCLE = "dhw_thermal_cleanse_cycle" _PARAM_GAS_TYPE = "gas_type" @@ -343,6 +346,7 @@ class AristonHandler: _PARAM_HEATING_LAST_7D_LIST, _PARAM_HEATING_LAST_30D_LIST, _PARAM_HEATING_LAST_365D_LIST, + _PARAM_HEATING_TODAY, _PARAM_WATER_LAST_24H, _PARAM_WATER_LAST_7D, _PARAM_WATER_LAST_30D, @@ -351,6 +355,7 @@ class AristonHandler: _PARAM_WATER_LAST_7D_LIST, _PARAM_WATER_LAST_30D_LIST, _PARAM_WATER_LAST_365D_LIST, + _PARAM_WATER_TODAY, _PARAM_COOLING_LAST_24H, _PARAM_COOLING_LAST_7D, _PARAM_COOLING_LAST_30D, @@ -358,7 +363,8 @@ class AristonHandler: _PARAM_COOLING_LAST_24H_LIST, _PARAM_COOLING_LAST_7D_LIST, _PARAM_COOLING_LAST_30D_LIST, - _PARAM_COOLING_LAST_365D_LIST + _PARAM_COOLING_LAST_365D_LIST, + _PARAM_COOLING_TODAY } _GET_REQUEST_MAIN = { _PARAM_CH_DETECTED_TEMPERATURE, @@ -526,16 +532,19 @@ def _update_units(self): self._ariston_sensors[self._PARAM_HEATING_LAST_7D][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_HEATING_LAST_30D][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_HEATING_LAST_365D][self._UNITS] = 'kBtuh' + self._ariston_sensors[self._PARAM_HEATING_TODAY][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_WATER_LAST_24H][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_WATER_LAST_7D][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_WATER_LAST_30D][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_WATER_LAST_365D][self._UNITS] = 'kBtuh' + self._ariston_sensors[self._PARAM_WATER_TODAY][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_SIGNAL_STRENGTH][self._UNITS] = '%' self._ariston_sensors[self._PARAM_THERMAL_CLEANSE_CYCLE][self._UNITS] = 'h' self._ariston_sensors[self._PARAM_COOLING_LAST_24H][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_COOLING_LAST_7D][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_COOLING_LAST_30D][self._UNITS] = 'kBtuh' self._ariston_sensors[self._PARAM_COOLING_LAST_365D][self._UNITS] = 'kBtuh' + self._ariston_sensors[self._PARAM_COOLING_TODAY][self._UNITS] = 'kBtuh' elif self._ariston_sensors[self._PARAM_UNITS][self._VALUE] == self._VAL_METRIC: self._ariston_sensors[self._PARAM_CH_ANTIFREEZE_TEMPERATURE][self._UNITS] = "°C" self._ariston_sensors[self._PARAM_CH_DETECTED_TEMPERATURE][self._UNITS] = "°C" @@ -556,16 +565,19 @@ def _update_units(self): self._ariston_sensors[self._PARAM_HEATING_LAST_7D][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_HEATING_LAST_30D][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_HEATING_LAST_365D][self._UNITS] = 'kWh' + self._ariston_sensors[self._PARAM_HEATING_TODAY][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_WATER_LAST_24H][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_WATER_LAST_7D][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_WATER_LAST_30D][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_WATER_LAST_365D][self._UNITS] = 'kWh' + self._ariston_sensors[self._PARAM_WATER_TODAY][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_SIGNAL_STRENGTH][self._UNITS] = '%' self._ariston_sensors[self._PARAM_THERMAL_CLEANSE_CYCLE][self._UNITS] = 'h' self._ariston_sensors[self._PARAM_COOLING_LAST_24H][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_COOLING_LAST_7D][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_COOLING_LAST_30D][self._UNITS] = 'kWh' self._ariston_sensors[self._PARAM_COOLING_LAST_365D][self._UNITS] = 'kWh' + self._ariston_sensors[self._PARAM_COOLING_TODAY][self._UNITS] = 'kWh' def __init__(self, username: str, @@ -1683,6 +1695,48 @@ def _set_sensors(self, request_type=""): self._ariston_sensors[self._PARAM_WATER_LAST_365D][self._VALUE] = None self._ariston_sensors[self._PARAM_WATER_LAST_365D_LIST][self._VALUE] = None + try: + sum_obj = 0 + start_hour = int(self._ariston_gas_data["daily"]["leftColumnLabel"]) + use_iterated = False + for item in self._ariston_gas_data["daily"]["data"]: + if start_hour == 0 or start_hour == 24: + use_iterated = True + start_hour += 2 + if use_iterated: + sum_obj = sum_obj + item["y3"] + self._ariston_sensors[self._PARAM_COOLING_TODAY][self._VALUE] = round(sum_obj, 3) + except KeyError: + self._ariston_sensors[self._PARAM_COOLING_TODAY][self._VALUE] = None + + try: + sum_obj = 0 + start_hour = int(self._ariston_gas_data["daily"]["leftColumnLabel"]) + use_iterated = False + for item in self._ariston_gas_data["daily"]["data"]: + if start_hour == 0 or start_hour == 24: + use_iterated = True + start_hour += 2 + if use_iterated: + sum_obj = sum_obj + item["y2"] + self._ariston_sensors[self._PARAM_HEATING_TODAY][self._VALUE] = round(sum_obj, 3) + except KeyError: + self._ariston_sensors[self._PARAM_HEATING_TODAY][self._VALUE] = None + + try: + sum_obj = 0 + start_hour = int(self._ariston_gas_data["daily"]["leftColumnLabel"]) + use_iterated = False + for item in self._ariston_gas_data["daily"]["data"]: + if start_hour == 0 or start_hour == 24: + use_iterated = True + start_hour += 2 + if use_iterated: + sum_obj = sum_obj + item["y"] + self._ariston_sensors[self._PARAM_WATER_TODAY][self._VALUE] = round(sum_obj, 3) + except KeyError: + self._ariston_sensors[self._PARAM_WATER_TODAY][self._VALUE] = None + else: self._ariston_sensors[self._PARAM_ACCOUNT_CH_GAS][self._VALUE] = None self._ariston_sensors[self._PARAM_ACCOUNT_DHW_GAS][self._VALUE] = None @@ -1712,6 +1766,9 @@ def _set_sensors(self, request_type=""): self._ariston_sensors[self._PARAM_HEATING_LAST_365D_LIST][self._VALUE] = None self._ariston_sensors[self._PARAM_WATER_LAST_365D_LIST][self._VALUE] = None self._ariston_sensors[self._PARAM_COOLING_LAST_365D_LIST][self._VALUE] = None + self._ariston_sensors[self._PARAM_COOLING_TODAY][self._VALUE] = None + self._ariston_sensors[self._PARAM_HEATING_TODAY][self._VALUE] = None + self._ariston_sensors[self._PARAM_WATER_TODAY][self._VALUE] = None if request_type == self._REQUEST_GET_OTHER: diff --git a/custom_components/ariston/const.py b/custom_components/ariston/const.py index 3eea34c..b45675a 100644 --- a/custom_components/ariston/const.py +++ b/custom_components/ariston/const.py @@ -21,6 +21,7 @@ PARAM_COOLING_LAST_7D_LIST = "cooling_last_7d_list" PARAM_COOLING_LAST_30D_LIST = "cooling_last_30d_list" PARAM_COOLING_LAST_365D_LIST = "cooling_last_365d_list" +PARAM_COOLING_TODAY = "cooling_today" PARAM_ERRORS = "errors" PARAM_ERRORS_COUNT = "errors_count" PARAM_DHW_COMFORT_FUNCTION = "dhw_comfort_function" @@ -40,6 +41,7 @@ PARAM_HEATING_LAST_7D_LIST = "heating_last_7d_list" PARAM_HEATING_LAST_30D_LIST = "heating_last_30d_list" PARAM_HEATING_LAST_365D_LIST = "heating_last_365d_list" +PARAM_HEATING_TODAY = "heating_today" PARAM_MODE = "mode" PARAM_OUTSIDE_TEMPERATURE = "outside_temperature" PARAM_SIGNAL_STRENGTH = "signal_strength" @@ -51,6 +53,7 @@ PARAM_WATER_LAST_7D_LIST = "water_last_7d_list" PARAM_WATER_LAST_30D_LIST = "water_last_30d_list" PARAM_WATER_LAST_365D_LIST = "water_last_365d_list" +PARAM_WATER_TODAY = "water_today" PARAM_UNITS = "units" PARAM_THERMAL_CLEANSE_CYCLE = "dhw_thermal_cleanse_cycle" PARAM_GAS_TYPE = "gas_type" diff --git a/custom_components/ariston/sensor.py b/custom_components/ariston/sensor.py index 0d17489..7ef7c9d 100644 --- a/custom_components/ariston/sensor.py +++ b/custom_components/ariston/sensor.py @@ -17,6 +17,11 @@ DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_VOLTAGE, + ENERGY_KILO_WATT_HOUR +) + +from homeassistant.components.sensor import ( + STATE_CLASS_TOTAL_INCREASING ) from .const import ( @@ -38,6 +43,7 @@ PARAM_COOLING_LAST_7D, PARAM_COOLING_LAST_30D, PARAM_COOLING_LAST_365D, + PARAM_COOLING_TODAY, PARAM_ERRORS, PARAM_ERRORS_COUNT, PARAM_DHW_COMFORT_FUNCTION, @@ -52,11 +58,13 @@ PARAM_HEATING_LAST_7D, PARAM_HEATING_LAST_30D, PARAM_HEATING_LAST_365D, + PARAM_HEATING_TODAY, PARAM_SIGNAL_STRENGTH, PARAM_WATER_LAST_24H, PARAM_WATER_LAST_7D, PARAM_WATER_LAST_30D, PARAM_WATER_LAST_365D, + PARAM_WATER_TODAY, PARAM_UNITS, PARAM_THERMAL_CLEANSE_CYCLE, PARAM_DHW_PROGRAM, @@ -111,51 +119,57 @@ SENSOR_GAS_TYPE = "Gas Type" SENSOR_GAS_COST = "Gas Cost" SENSOR_ELECTRICITY_COST = "Electricity Cost" +SENSOR_COOLING_TODAY = "Energy use for Cooling today" +SENSOR_HETING_TODAY = "Energy use for Heating today" +SENSOR_WATER_TODAY = "Energy use for Water today" _LOGGER = logging.getLogger(__name__) # Sensor types are defined like: Name, units, icon SENSORS = { - PARAM_ACCOUNT_CH_GAS: [SENSOR_ACCOUNT_CH_GAS, None, "mdi:cash"], - PARAM_ACCOUNT_DHW_GAS: [SENSOR_ACCOUNT_DHW_GAS, None, "mdi:cash"], - PARAM_ACCOUNT_CH_ELECTRICITY: [SENSOR_ACCOUNT_CH_ELECTRICITY, None, "mdi:cash"], - PARAM_ACCOUNT_DHW_ELECTRICITY: [SENSOR_ACCOUNT_DHW_ELECTRICITY, None, "mdi:cash"], - PARAM_CH_ANTIFREEZE_TEMPERATURE: [SENSOR_CH_ANTIFREEZE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator"], - PARAM_CH_DETECTED_TEMPERATURE: [SENSOR_CH_DETECTED_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:thermometer"], - PARAM_CH_MODE: [SENSOR_CH_MODE, None, "mdi:radiator"], - PARAM_CH_SET_TEMPERATURE: [SENSOR_CH_SET_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator"], - PARAM_CH_PROGRAM: [SENSOR_CH_PROGRAM, None, "mdi:calendar-month"], - PARAM_CH_COMFORT_TEMPERATURE: [SENSOR_CH_COMFORT_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator"], - PARAM_CH_ECONOMY_TEMPERATURE: [SENSOR_CH_ECONOMY_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator"], - PARAM_CH_WATER_TEMPERATURE: [SENSOR_CH_WATER_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator"], - PARAM_COOLING_LAST_24H: [SENSOR_COOLING_LAST_24H, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_COOLING_LAST_7D: [SENSOR_COOLING_LAST_7D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_COOLING_LAST_30D: [SENSOR_COOLING_LAST_30D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_COOLING_LAST_365D: [SENSOR_COOLING_LAST_365D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_DHW_PROGRAM: [SENSOR_DHW_PROGRAM, None, "mdi:calendar-month"], - PARAM_DHW_COMFORT_FUNCTION: [SENSOR_DHW_COMFORT_FUNCTION, None, "mdi:water-pump"], - PARAM_DHW_SET_TEMPERATURE: [SENSOR_DHW_SET_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump"], - PARAM_DHW_STORAGE_TEMPERATURE: [SENSOR_DHW_STORAGE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump"], - PARAM_DHW_COMFORT_TEMPERATURE: [SENSOR_DHW_COMFORT_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump"], - PARAM_DHW_ECONOMY_TEMPERATURE: [SENSOR_DHW_ECONOMY_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump"], - PARAM_DHW_MODE: [SENSOR_DHW_MODE, None, "mdi:water-pump"], - PARAM_ERRORS_COUNT: [SENSOR_ERRORS, None, "mdi:alert-outline"], - PARAM_HEATING_LAST_24H: [SENSOR_HEATING_LAST_24H, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_HEATING_LAST_7D: [SENSOR_HEATING_LAST_7D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_HEATING_LAST_30D: [SENSOR_HEATING_LAST_30D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_HEATING_LAST_365D: [SENSOR_HEATING_LAST_365D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_MODE: [SENSOR_MODE, None, "mdi:water-boiler"], - PARAM_OUTSIDE_TEMPERATURE: [SENSOR_OUTSIDE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:thermometer"], - PARAM_SIGNAL_STRENGTH: [SENSOR_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH, "mdi:signal"], - PARAM_WATER_LAST_24H: [SENSOR_WATER_LAST_24H, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_WATER_LAST_7D: [SENSOR_WATER_LAST_7D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_WATER_LAST_30D: [SENSOR_WATER_LAST_30D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_WATER_LAST_365D: [SENSOR_WATER_LAST_365D, DEVICE_CLASS_ENERGY, "mdi:cash"], - PARAM_UNITS: [SENSOR_UNITS, None, "mdi:scale-balance"], - PARAM_THERMAL_CLEANSE_CYCLE: [SENSOR_THERMAL_CLEANSE_CYCLE, DEVICE_CLASS_TIMESTAMP, "mdi:update"], - PARAM_GAS_TYPE: [SENSOR_GAS_TYPE, None, "mdi:gas-cylinder"], - PARAM_GAS_COST: [SENSOR_GAS_COST, None, "mdi:cash"], - PARAM_ELECTRICITY_COST: [SENSOR_ELECTRICITY_COST, None, "mdi:cash"], + PARAM_ACCOUNT_CH_GAS: [SENSOR_ACCOUNT_CH_GAS, None, "mdi:cash", None], + PARAM_ACCOUNT_DHW_GAS: [SENSOR_ACCOUNT_DHW_GAS, None, "mdi:cash", None], + PARAM_ACCOUNT_CH_ELECTRICITY: [SENSOR_ACCOUNT_CH_ELECTRICITY, None, "mdi:cash", None], + PARAM_ACCOUNT_DHW_ELECTRICITY: [SENSOR_ACCOUNT_DHW_ELECTRICITY, None, "mdi:cash", None], + PARAM_CH_ANTIFREEZE_TEMPERATURE: [SENSOR_CH_ANTIFREEZE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator", None], + PARAM_CH_DETECTED_TEMPERATURE: [SENSOR_CH_DETECTED_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:thermometer", None], + PARAM_CH_MODE: [SENSOR_CH_MODE, None, "mdi:radiator", None], + PARAM_CH_SET_TEMPERATURE: [SENSOR_CH_SET_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator", None], + PARAM_CH_PROGRAM: [SENSOR_CH_PROGRAM, None, "mdi:calendar-month", None], + PARAM_CH_COMFORT_TEMPERATURE: [SENSOR_CH_COMFORT_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator", None], + PARAM_CH_ECONOMY_TEMPERATURE: [SENSOR_CH_ECONOMY_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator", None], + PARAM_CH_WATER_TEMPERATURE: [SENSOR_CH_WATER_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:radiator", None], + PARAM_COOLING_LAST_24H: [SENSOR_COOLING_LAST_24H, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_COOLING_LAST_7D: [SENSOR_COOLING_LAST_7D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_COOLING_LAST_30D: [SENSOR_COOLING_LAST_30D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_COOLING_LAST_365D: [SENSOR_COOLING_LAST_365D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_DHW_PROGRAM: [SENSOR_DHW_PROGRAM, None, "mdi:calendar-month", None], + PARAM_DHW_COMFORT_FUNCTION: [SENSOR_DHW_COMFORT_FUNCTION, None, "mdi:water-pump", None], + PARAM_DHW_SET_TEMPERATURE: [SENSOR_DHW_SET_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump", None], + PARAM_DHW_STORAGE_TEMPERATURE: [SENSOR_DHW_STORAGE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump", None], + PARAM_DHW_COMFORT_TEMPERATURE: [SENSOR_DHW_COMFORT_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump", None], + PARAM_DHW_ECONOMY_TEMPERATURE: [SENSOR_DHW_ECONOMY_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:water-pump", None], + PARAM_DHW_MODE: [SENSOR_DHW_MODE, None, "mdi:water-pump", None], + PARAM_ERRORS_COUNT: [SENSOR_ERRORS, None, "mdi:alert-outline", None], + PARAM_HEATING_LAST_24H: [SENSOR_HEATING_LAST_24H, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_HEATING_LAST_7D: [SENSOR_HEATING_LAST_7D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_HEATING_LAST_30D: [SENSOR_HEATING_LAST_30D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_HEATING_LAST_365D: [SENSOR_HEATING_LAST_365D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_MODE: [SENSOR_MODE, None, "mdi:water-boiler", None], + PARAM_OUTSIDE_TEMPERATURE: [SENSOR_OUTSIDE_TEMPERATURE, DEVICE_CLASS_TEMPERATURE, "mdi:thermometer", None], + PARAM_SIGNAL_STRENGTH: [SENSOR_SIGNAL_STRENGTH, DEVICE_CLASS_SIGNAL_STRENGTH, "mdi:signal", None], + PARAM_WATER_LAST_24H: [SENSOR_WATER_LAST_24H, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_WATER_LAST_7D: [SENSOR_WATER_LAST_7D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_WATER_LAST_30D: [SENSOR_WATER_LAST_30D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_WATER_LAST_365D: [SENSOR_WATER_LAST_365D, DEVICE_CLASS_ENERGY, "mdi:cash", None], + PARAM_UNITS: [SENSOR_UNITS, None, "mdi:scale-balance", None], + PARAM_THERMAL_CLEANSE_CYCLE: [SENSOR_THERMAL_CLEANSE_CYCLE, DEVICE_CLASS_TIMESTAMP, "mdi:update", None], + PARAM_GAS_TYPE: [SENSOR_GAS_TYPE, None, "mdi:gas-cylinder", None], + PARAM_GAS_COST: [SENSOR_GAS_COST, None, "mdi:cash", None], + PARAM_ELECTRICITY_COST: [SENSOR_ELECTRICITY_COST, None, "mdi:cash", None], + PARAM_COOLING_TODAY: [SENSOR_COOLING_TODAY, DEVICE_CLASS_ENERGY, "mdi:cash", STATE_CLASS_TOTAL_INCREASING], + PARAM_HEATING_TODAY: [SENSOR_HETING_TODAY, DEVICE_CLASS_ENERGY, "mdi:cash", STATE_CLASS_TOTAL_INCREASING], + PARAM_WATER_TODAY: [SENSOR_WATER_TODAY, DEVICE_CLASS_ENERGY, "mdi:cash", STATE_CLASS_TOTAL_INCREASING], } @@ -188,6 +202,7 @@ def __init__(self, name, device, sensor_type): self._attrs = {} self._icon = SENSORS[sensor_type][2] self._device_class = SENSORS[sensor_type][1] + self._state_class = SENSORS[sensor_type][3] @property def unique_id(self): @@ -204,6 +219,24 @@ def state(self): """Return the state of the sensor.""" return self._state + @property + def native_value(self): + """Return value of sensor.""" + return self._state + + @property + def state_class(self): + """State class of sensor.""" + return self._state_class + + @property + def native_unit_of_measurement(self): + """Return unit of sensor.""" + try: + return self._api.sensor_values[self._sensor_type][UNITS] + except KeyError: + return None + @property def device_class(self): """Return device class.""" @@ -274,7 +307,9 @@ def update(self): self._attrs["Min"] = None self._attrs["Max"] = None - elif self._sensor_type == PARAM_ERRORS_COUNT: + elif self._sensor_type in { + PARAM_ERRORS_COUNT + }: self._attrs = self._api.sensor_values[PARAM_ERRORS][VALUE] elif self._sensor_type in { @@ -294,8 +329,19 @@ def update(self): list_param = self._sensor_type + "_list" self._attrs = self._api.sensor_values[list_param][VALUE] - elif self._sensor_type in {PARAM_CH_PROGRAM, PARAM_DHW_PROGRAM}: + elif self._sensor_type in { + PARAM_CH_PROGRAM, + PARAM_DHW_PROGRAM + }: if not self._api.sensor_values[self._sensor_type][VALUE] is None: self._attrs = self._api.sensor_values[self._sensor_type][VALUE] + + elif self._sensor_type in { + PARAM_WATER_TODAY, + PARAM_HEATING_TODAY, + PARAM_COOLING_TODAY + }: + self._attrs["state_class"] = self._state_class + except KeyError: _LOGGER.warning("Problem updating sensors for Ariston")