Skip to content

Commit

Permalink
Merge pull request #2 from smarthomepch/adding-logging
Browse files Browse the repository at this point in the history
added logging support
  • Loading branch information
chomupashchuk authored Jan 31, 2021
2 parents a3270ef + 9b605fe commit 985b9ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions aristonremotethermo/ariston.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,15 @@ class AristonHandler:
'dhw_unknown_as_on' - indicates if to assume 'dhw_flame' as being True if cannot be identified.
'logging_level' - defines level of logging - allowed values [CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET=(default)]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

_VERSION = "1.0.28"

_LOGGER = logging.getLogger(__name__)
_LOGGING_LEVELS = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]

_PARAM_ACCOUNT_CH_GAS = "account_ch_gas"
_PARAM_ACCOUNT_CH_ELECTRICITY = "account_ch_electricity"
Expand Down Expand Up @@ -544,6 +547,7 @@ def __init__(self,
units: str = _UNIT_METRIC,
ch_and_dhw: bool = False,
dhw_unknown_as_on: bool = True,
logging_level: str = "NOTSET",
) -> None:
"""
Initialize API.
Expand Down Expand Up @@ -576,6 +580,9 @@ def __init__(self,
if not isinstance(sensors, list):
raise Exception("Invalid sensors type")

if logging_level not in self._LOGGING_LEVELS:
raise Exception("Invalid logging_level")

if sensors:
for sensor in sensors:
if sensor not in self._SENSOR_LIST:
Expand All @@ -589,6 +596,17 @@ def __init__(self,
if not os.path.isdir(self._store_folder):
os.makedirs(self._store_folder)

"""
Logging settings
"""
self._logging_level = logging.getLevelName(logging_level)
self._LOGGER.setLevel(self._logging_level)
self._console_handler = logging.StreamHandler()
self._console_handler.setLevel(self._logging_level)
self._formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
self._console_handler.setFormatter(self._formatter)
self._LOGGER.addHandler(self._console_handler)

# clear read sensor values
self._ariston_sensors = {}
for sensor in self._SENSOR_LIST:
Expand Down
18 changes: 18 additions & 0 deletions aristonremotethermo/aristonaqua.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,15 @@ class AquaAristonHandler:
'store_folder' - folder to store HTTP and internal data to. If empty string is used, then current working directory
is used with a folder 'http_logs' within it.
'logging_level' - defines level of logging - allowed values [CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET=(default)]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"""

_VERSION = "1.0.28"

_LOGGER = logging.getLogger(__name__)
_LOGGING_LEVELS = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]

_VALUE = "value"
_UNITS = "units"
Expand Down Expand Up @@ -301,6 +304,7 @@ def __init__(self,
polling: Union[float, int] = 1.,
store_file: bool = False,
store_folder: str = "",
logging_level: str = "NOTSET",
) -> None:
"""
Initialize API.
Expand All @@ -324,6 +328,9 @@ def __init__(self,
if boiler_type not in self._SUPPORTED_BOILER_TYPES:
raise Exception("Unknown boiler type")

if logging_level not in self._LOGGING_LEVELS:
raise Exception("Invalid logging_level")

if sensors:
for sensor in sensors:
if sensor not in self._SENSOR_LIST:
Expand All @@ -337,6 +344,17 @@ def __init__(self,
if not os.path.isdir(self._store_folder):
os.makedirs(self._store_folder)

"""
Logging settings
"""
self._logging_level = logging.getLevelName(logging_level)
self._LOGGER.setLevel(self._logging_level)
self._console_handler = logging.StreamHandler()
self._console_handler.setLevel(self._logging_level)
self._formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
self._console_handler.setFormatter(self._formatter)
self._LOGGER.addHandler(self._console_handler)

self._ariston_sensors = {}
for sensor_all in self._SENSOR_LIST:
self._ariston_sensors[sensor_all] = {}
Expand Down

0 comments on commit 985b9ba

Please sign in to comment.