diff --git a/ThermiaOnlineAPI/api/ThermiaAPI.py b/ThermiaOnlineAPI/api/ThermiaAPI.py index c7327a7..11307e8 100644 --- a/ThermiaOnlineAPI/api/ThermiaAPI.py +++ b/ThermiaOnlineAPI/api/ThermiaAPI.py @@ -7,7 +7,7 @@ from ..exceptions.NetworkException import NetworkException from ..model.HeatPump import ThermiaHeatPump -LOGGER = logging.getLogger(__name__) +_LOGGER = logging.getLogger(__name__) THERMIA_API_CONFIG_URL = "https://online.thermia.se/api/configuration" THERMIA_INSTALLATION_PATH = "/api/v1/Registers/Installations/" @@ -34,10 +34,9 @@ def get_devices(self): url = self.configuration["apiBaseUrl"] + "/api/v1/InstallationsInfo/own" request = requests.get(url, headers=self.__default_request_headers) status = request.status_code - LOGGER.info("Fetching devices. " + str(status)) if status != 200: - LOGGER.error("Error fetching devices. " + str(status)) + _LOGGER.error("Error fetching devices. " + str(status)) return [] return request.json() @@ -50,7 +49,7 @@ def get_device_by_id(self, device_id: str): device = [d for d in devices if str(d["id"]) == device_id] if len(device) != 1: - LOGGER.error("Error getting device by id: " + str(device_id)) + _LOGGER.error("Error getting device by id: " + str(device_id)) return None return device[0] @@ -63,7 +62,7 @@ def get_device_info(self, device_id: str): status = request.status_code if status != 200: - LOGGER.error("Error fetching device info. " + str(status)) + _LOGGER.error("Error fetching device info. " + str(status)) return None return request.json() @@ -81,7 +80,7 @@ def get_device_status(self, device_id: str): status = request.status_code if status != 200: - LOGGER.error("Error fetching device status. " + str(status)) + _LOGGER.error("Error fetching device status. " + str(status)) return None return request.json() @@ -99,12 +98,14 @@ def get_temperature_status(self, device: ThermiaHeatPump): status = request.status_code if status != 200: - LOGGER.error("Error in getting device's temperature status. " + str(status)) + _LOGGER.error( + "Error in getting device's temperature status. " + str(status) + ) return None device_temperature_register_index = device.get_register_indexes()["temperature"] if device_temperature_register_index is None: - LOGGER.error( + _LOGGER.error( "Error in getting device's temperature status. No temperature register index." ) return None @@ -140,7 +141,7 @@ def get_operation_mode(self, device: ThermiaHeatPump): status = request.status_code if status != 200: - LOGGER.error("Error in getting device's operation mode. " + str(status)) + _LOGGER.error("Error in getting device's operation mode. " + str(status)) return None data = [d for d in request.json() if d["registerName"] == "REG_OPERATIONMODE"] @@ -185,7 +186,7 @@ def get_hot_water_switch_state(self, device: ThermiaHeatPump): status = request.status_code if status != 200: - LOGGER.error("Error in getting device's operation mode. " + str(status)) + _LOGGER.error("Error in getting device's operation mode. " + str(status)) return None data = [ @@ -211,7 +212,7 @@ def get_hot_water_switch_state(self, device: ThermiaHeatPump): def set_temperature(self, device: ThermiaHeatPump, temperature): device_temperature_register_index = device.get_register_indexes()["temperature"] if device_temperature_register_index is None: - LOGGER.error( + _LOGGER.error( "Error setting device's temperature. No temperature register index." ) return @@ -227,7 +228,7 @@ def set_operation_mode(self, device: ThermiaHeatPump, mode): "operation_mode" ] if device_operation_mode_register_index is None: - LOGGER.error( + _LOGGER.error( "Error setting device's operation mode. No operation mode register index." ) return @@ -243,7 +244,7 @@ def set_hot_water_switch_state( "hot_water_switch" ] if device_hot_water_switch_state_register_index is None: - LOGGER.error( + _LOGGER.error( "Error setting device's hot water switch state. No hot water switch register index." ) return @@ -273,7 +274,7 @@ def __set_register_value( status = request.status_code if status != 200: - LOGGER.error( + _LOGGER.error( "Error setting register " + str(register_index) + " value. " @@ -285,7 +286,7 @@ def __fetch_configuration(self): status = request.status_code if status != 200: - LOGGER.error("Error fetching API configuration. " + str(status)) + _LOGGER.error("Error fetching API configuration. " + str(status)) raise NetworkException("Error fetching API configuration.", status) return request.json() @@ -302,7 +303,7 @@ def __authenticate(self): status = request_auth.status_code if status != 200: - LOGGER.error( + _LOGGER.error( "Authentication request failed, please check credentials. " + str(status) ) @@ -311,7 +312,7 @@ def __authenticate(self): ) auth_data = request_auth.json() - LOGGER.debug(str(auth_data)) + _LOGGER.debug(str(auth_data)) token_valid_to = auth_data.get("tokenValidToUtc").split(".")[0] datetime_object = datetime.strptime(token_valid_to, "%Y-%m-%dT%H:%M:%S") @@ -325,7 +326,7 @@ def __authenticate(self): "Content-Type": "application/json", } - LOGGER.info("Authentication was successful, token set.") + _LOGGER.info("Authentication was successful, token set.") return True def __check_token_validity(self): @@ -333,5 +334,5 @@ def __check_token_validity(self): self.__token_valid_to is None or self.__token_valid_to < datetime.now().timestamp() ): - LOGGER.info("Token expired, reauthenticating.") + _LOGGER.info("Token expired, reauthenticating.") self.authenticated = self.__authenticate()