Skip to content

Commit

Permalink
Logger updates and maximu temperature fetching for Lydos Hybrid
Browse files Browse the repository at this point in the history
  • Loading branch information
chomupashchuk committed Jan 31, 2021
1 parent 985b9ba commit 6890a69
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 61 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Version 1.0.29
- Logging to console included;
- Lydos Hybrid maximum value update;

# Version 1.0.28
- CH Water temperature added in AristonHandler for supported models;

Expand Down
20 changes: 17 additions & 3 deletions aristonremotethermo/ariston.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,24 @@ class AristonHandler:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

_VERSION = "1.0.28"
_VERSION = "1.0.29"

_LOGGER = logging.getLogger(__name__)
_LOGGING_LEVELS = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]
_LEVEL_CRITICAL = "CRITICAL"
_LEVEL_ERROR = "ERROR"
_LEVEL_WARNING = "WARNING"
_LEVEL_INFO = "INFO"
_LEVEL_DEBUG = "DEBUG"
_LEVEL_NOTSET = "NOTSET"

_LOGGING_LEVELS = [
_LEVEL_CRITICAL,
_LEVEL_ERROR,
_LEVEL_WARNING,
_LEVEL_INFO,
_LEVEL_DEBUG,
_LEVEL_NOTSET
]

_PARAM_ACCOUNT_CH_GAS = "account_ch_gas"
_PARAM_ACCOUNT_CH_ELECTRICITY = "account_ch_electricity"
Expand Down Expand Up @@ -547,7 +561,7 @@ def __init__(self,
units: str = _UNIT_METRIC,
ch_and_dhw: bool = False,
dhw_unknown_as_on: bool = True,
logging_level: str = "NOTSET",
logging_level: str = _LEVEL_NOTSET,
) -> None:
"""
Initialize API.
Expand Down
155 changes: 98 additions & 57 deletions aristonremotethermo/aristonaqua.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,24 @@ class AquaAristonHandler:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

_VERSION = "1.0.28"
_VERSION = "1.0.29"

_LOGGER = logging.getLogger(__name__)
_LOGGING_LEVELS = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]
_LEVEL_CRITICAL = "CRITICAL"
_LEVEL_ERROR = "ERROR"
_LEVEL_WARNING = "WARNING"
_LEVEL_INFO = "INFO"
_LEVEL_DEBUG = "DEBUG"
_LEVEL_NOTSET = "NOTSET"

_LOGGING_LEVELS = [
_LEVEL_CRITICAL,
_LEVEL_ERROR,
_LEVEL_WARNING,
_LEVEL_INFO,
_LEVEL_DEBUG,
_LEVEL_NOTSET
]

_VALUE = "value"
_UNITS = "units"
Expand Down Expand Up @@ -304,7 +318,7 @@ def __init__(self,
polling: Union[float, int] = 1.,
store_file: bool = False,
store_folder: str = "",
logging_level: str = "NOTSET",
logging_level: str = _LEVEL_NOTSET,
) -> None:
"""
Initialize API.
Expand Down Expand Up @@ -394,6 +408,8 @@ def __init__(self,
self._val_to_mode = self._VALUE_TO_MODE_LYDOS_HYBRID
self._boiler_str = "se"

self._max_temp_boiler = 80
self._max_temp_green = 53
self._showers_required_temp = 0
self._showers_mode = self._VAL_SHOWERS
# clear configuration data
Expand Down Expand Up @@ -668,14 +684,12 @@ def supported_sensors_set_values(self) -> dict:
elif parameter == self._PARAM_REQUIRED_TEMPERATURE:
param_values = dict()
param_values["min"] = 40.
param_values["step"] = 1.
if self._boiler_type != self._TYPE_LYDOS_HYBRID:
param_values["max"] = 80.
else:
param_values["max"] = 70.
param_values["max"] = self._max_temp_boiler
if self._boiler_type == self._TYPE_LYDOS_HYBRID:
if self._ariston_sensors and self._PARAM_MODE in self._ariston_sensors:
if self._ariston_sensors[self._PARAM_MODE][self._VALUE] in {self._MODE_GREEN}:
param_values["max"] = 53.
param_values["max"] = self._max_temp_green
param_values["step"] = 1.
sensors_dictionary[parameter] = param_values
elif parameter == self._PARAM_REQUIRED_SHOWERS:
param_values = dict()
Expand Down Expand Up @@ -794,29 +808,43 @@ def _login_session(self):
else:
self._LOGGER.warning('%s Authentication login error', self)
raise Exception("Login parsing of URL failed")
url = self._url + '/api/v2/velis/plants?appId=com.remotethermo.velis'
try:
resp = self._session.get(
url,
auth=self._token,
timeout=self._timeout_long,
verify=True)
except requests.exceptions.RequestException:
self._LOGGER.warning('%s Authentication model fetch error', self)
raise Exception("Model fetch exception")
if resp.status_code != 200:
if self._store_file:
if not os.path.isdir(self._store_folder):
os.makedirs(self._store_folder)
store_file = "data_ariston_model_" + str(resp.status_code) + "_error.txt"
store_file_path = os.path.join(self._store_folder, store_file)
with open(store_file_path, "w") as f:
f.write(resp.text)
self._LOGGER.warning('%s Unexpected reply during model fetch: %s', self, resp.status_code)
raise Exception("Model unexpected reply code")
if not self._json_validator(resp.json()):
self._LOGGER.warning('%s Model fetch not JSON', self)
raise Exception("Model fetch not JSON")

with self._plant_id_lock:
self._plant_id = plan_id

# self._model_fetch()

if self._boiler_type == self._TYPE_LYDOS_HYBRID:
self._fetch_max_temp()

with self._plant_id_lock:
self._login = True
self._LOGGER.info('%s Plant ID is %s', self, self._plant_id)
return

def _model_fetch(self):
"""Fetch model data"""
url = f"{self._url}/api/v2/velis/plants?appId=com.remotethermo.velis"
try:
resp = self._session.get(
url,
auth=self._token,
timeout=self._timeout_long,
verify=True)
except requests.exceptions.RequestException:
self._LOGGER.warning('%s Authentication model fetch error', self)
raise Exception("Model fetch exception")
if resp.status_code != 200:
if self._store_file:
if not os.path.isdir(self._store_folder):
os.makedirs(self._store_folder)
store_file = "data_ariston_model_" + str(resp.status_code) + "_error.txt"
store_file_path = os.path.join(self._store_folder, store_file)
with open(store_file_path, "w") as f:
f.write(resp.text)
self._LOGGER.warning('%s Unexpected reply during model fetch: %s', self, resp.status_code)
raise Exception("Model unexpected reply code")
if self._json_validator(resp.json()):
for plant_instance in resp.json():
if self._store_file:
if not os.path.isdir(self._store_folder):
Expand All @@ -825,31 +853,44 @@ def _login_session(self):
store_file_path = os.path.join(self._store_folder, store_file)
with open(store_file_path, 'w') as ariston_fetched:
json.dump(resp.json(), ariston_fetched)
# if 'gw' in plant_instance and plant_instance["gw"] == plan_id:
# if "name" in plant_instance and "lydos" in plant_instance["name"].lower():
# self._boiler_type = self._TYPE_LYDOS_HYBRID
# self._boiler_str = "se"
# self._mode_to_val = self._MODE_TO_VALUE_LYDOS_HYBRID
# self._val_to_mode = self._VALUE_TO_MODE_LYDOS_HYBRID
# elif "wheType" in plant_instance and plant_instance["wheType"] == 1:
# self._boiler_type = self._TYPE_VELIS
# elif "wheModelType" in plant_instance and plant_instance["wheModelType"] == 1:
# self._boiler_type = self._TYPE_VELIS
#
# if self._boiler_type == self._TYPE_VELIS:
# # presumably it is Velis, which uses showers instead of temperatures
# self._valid_requests[self._REQUEST_GET_SHOWERS] = True
# if self._REQUEST_GET_SHOWERS not in self._request_list_high_prio:
# self._request_list_high_prio.insert(1, self._REQUEST_GET_SHOWERS)
# self._showers_mode = self._VAL_SHOWERS
# self._read_showers_temp()
# if not os.path.isdir(self._store_folder):
# os.makedirs(self._store_folder)
with self._plant_id_lock:
self._plant_id = plan_id
self._login = True
self._LOGGER.info('%s Plant ID is %s', self, self._plant_id)
return

def _fetch_max_temp(self):
"""Fetch maximum temperature"""
url = f"{self._url}/api/v2/velis/sePlantData/{self._plant_id}/plantSettings?appId=com.remotethermo.velis"
for attempt in range(5):
try:
resp = self._session.get(
url,
auth=self._token,
timeout=self._timeout_long,
verify=True)
except requests.exceptions.RequestException as ex:
self._LOGGER.warning('%s Could not fetch maximum: %s', self, ex)
time.sleep(5)
continue
else:

if resp.status_code != 200 or not self._json_validator(resp.json()):
self._LOGGER.warning('%s Could not fetch maximum', self)
time.sleep(5)
continue

try:
self._max_temp_boiler = resp.json()["SeMaxSetpointTemperature"]
self._max_temp_green = resp.json()["SeMaxGreenSetpointTemperature"]

if self._store_file:
if not os.path.isdir(self._store_folder):
os.makedirs(self._store_folder)
store_file = 'lydos_max_temperatures.json'
store_file_path = os.path.join(self._store_folder, store_file)
with open(store_file_path, 'w') as ariston_fetched:
json.dump(resp.json(), ariston_fetched)
break

except Exception:
self._max_temp_boiler = 75
continue

def _set_sensors(self, request_type=""):

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup_args = dict(
name='aristonremotethermo',
version='1.0.28',
version='1.0.29',
description='Ariston NET Remotethermo integration',
long_description_content_type="text/markdown",
long_description=README + '\n\n' + HISTORY,
Expand Down

0 comments on commit 6890a69

Please sign in to comment.