Skip to content

Commit

Permalink
todays sensors handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chomupashchuk committed Dec 10, 2021
1 parent 9b07f7d commit fdeba7e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 41 deletions.
94 changes: 54 additions & 40 deletions custom_components/ariston/ariston.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class AristonHandler:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

_VERSION = "1.0.47"
_VERSION = "1.0.48"

_LOGGER = logging.getLogger(__name__)
_LEVEL_CRITICAL = "CRITICAL"
Expand Down Expand Up @@ -287,6 +287,7 @@ def duplicate_set_per_zone(var_name, locals_dict, zone_params, zone_start, zone_
_MAX_ERRORS = 10
_MAX_ERRORS_TIMER_EXTEND = 7
_MAX_ZERO_TOLERANCE = 10
_MAX_ZERO_TOLERANCE_TODAY_PARAMS = 5
_HTTP_DELAY_MULTIPLY = 3
_HTTP_TIMER_SET_LOCK = 25
_HTTP_TIMER_SET_WAIT = 30
Expand All @@ -296,6 +297,8 @@ def duplicate_set_per_zone(var_name, locals_dict, zone_params, zone_start, zone_
_HTTP_TIMEOUT_GET_SHORT = 6.0
_HTTP_PARAM_DELAY = 30.0

_TODAY_SENSORS = {_PARAM_COOLING_TODAY, _PARAM_HEATING_TODAY, _PARAM_WATER_TODAY}

# Conversions between parameters
_MODE_TO_VALUE = {_VAL_WINTER: 1, _VAL_SUMMER: 0, _VAL_OFF: 5, _VAL_HEATING_ONLY: 2, _VAL_COOLING: 3}
_VALUE_TO_MODE = {value: key for (key, value) in _MODE_TO_VALUE.items()}
Expand Down Expand Up @@ -893,6 +896,9 @@ def __init__(self,
self._REQUEST_GET_OTHER: False,
self._REQUEST_GET_UNITS: False
}
self._today_count_ignore = dict()
for today_param in self._TODAY_SENSORS:
self._today_count_ignore[today_param] = 0
self._set_retry = {
self._REQUEST_SET_MAIN: 0,
self._REQUEST_SET_OTHER: 0,
Expand Down Expand Up @@ -1915,47 +1921,53 @@ def _set_sensors(self, request_type="", zone_number=_ZONE_1):
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
new_todays_values = dict()
old_todays_values = dict()

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
for today_sensor in self._TODAY_SENSORS:
try:
if today_sensor == self._PARAM_COOLING_TODAY:
key = "y3"
elif today_sensor == self._PARAM_HEATING_TODAY:
key = "y2"
elif today_sensor == self._PARAM_WATER_TODAY:
key = "y"
else:
# Unknown key
continue
# Store old values
old_todays_values[today_sensor] = self._ariston_sensors[today_sensor][self._VALUE]
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[key]
new_todays_values[today_sensor] = round(sum_obj, 3)
except KeyError:
new_todays_values[today_sensor] = None
continue

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
if all(new_todays_values[today_sensor] == 0 for today_sensor in self._TODAY_SENSORS):
all_zero = True
else:
all_zero = False

for today_sensor in self._TODAY_SENSORS:
try:
if all_zero and old_todays_values[today_sensor] and self._today_count_ignore < self._MAX_ZERO_TOLERANCE_TODAY_PARAMS:
# Use old value if reports are all 0, old value is non-zero and we have not exceeded tolarance
self._ariston_sensors[today_sensor][self._VALUE] = old_todays_values[today_sensor]
self._today_count_ignore[today_sensor] += 1
else:
# Use new value
self._ariston_sensors[today_sensor][self._VALUE] = new_todays_values[today_sensor]
self._today_count_ignore[today_sensor] = 0
except:
continue

else:
for parameter in self._GET_REQUEST_GAS:
Expand Down Expand Up @@ -3904,6 +3916,8 @@ def _clear_data(self):
self._ZONE_2: dict(),
self._ZONE_3: dict()
}
for today_param in self._TODAY_SENSORS:
self._today_count_ignore[today_param] = 0
for sensor in self._SENSOR_LIST:
if sensor in self._ariston_sensors and sensor != self._PARAM_UNITS:
self._ariston_sensors[sensor][self._VALUE] = None
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ariston/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"requirements": [],
"dependencies": [],
"codeowners": ["@chomupashchuk"],
"version": "1.0.47"
"version": "1.0.48"
}

0 comments on commit fdeba7e

Please sign in to comment.