From 7159c0cda477eb61311254c76415339a2a7c3f3e Mon Sep 17 00:00:00 2001 From: Krisjanis Lejejs Date: Sun, 26 Dec 2021 18:15:00 +0200 Subject: [PATCH] Code refactoring --- README.md | 34 +++++++------- ThermiaOnlineAPI/__init__.py | 12 ++--- ThermiaOnlineAPI/api/ThermiaAPI.py | 8 ++-- .../model/{WaterHeater.py => HeatPump.py} | 2 +- ThermiaOnlineAPI/model/__init__.py | 2 +- example.py | 46 +++++++++---------- setup.py | 2 +- 7 files changed, 53 insertions(+), 53 deletions(-) rename ThermiaOnlineAPI/model/{WaterHeater.py => HeatPump.py} (99%) diff --git a/README.md b/README.md index 25a360d..4111b37 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,29 @@ # Thermia Online API ### A Python API for Thermia heat pumps using https://online.thermia.se -## Available properties within ThermiaWaterHeater class: +## Available properties within ThermiaHeatPump class: | Property | Description | | --- | --- | -| `name` | Name of the Water Heater | -| `id` | Unique ID of the Water Heater Thermia generates | -| `is_online` | Boolean value indicating if the Water Heater is online or not | -| `last_online` | DateTime string indicating the last time the Water Heater was online | -| `has_indoor_temperature_sensor` | Boolean value indicating if the Water Heater has an indoor temperature sensor | +| `name` | Name of the Heat Pump | +| `id` | Unique ID of the Heat Pump Thermia generates | +| `is_online` | Boolean value indicating if the Heat Pump is online or not | +| `last_online` | DateTime string indicating the last time the Heat Pump was online | +| `has_indoor_temperature_sensor` | Boolean value indicating if the Heat Pump has an indoor temperature sensor | | `indoor_temperature` | Indoor temperature in Celsius, if `has_indoor_temperature_sensor` is False, this value is the same as `heat_temperature` | -| `is_outdoor_temp_sensor_functioning` | Boolean value indicating if the Water Heater has an outdoor temperature sensor | +| `is_outdoor_temp_sensor_functioning` | Boolean value indicating if the Heat Pump has an outdoor temperature sensor | | `outdoor_temperature` | Outdoor temperature in Celsius | -| `is_hot_water_active` | Boolean value indicating if the Water Heater is heating water | +| `is_hot_water_active` | Boolean value indicating if the Heat Pump is heating water | | `hot_water_temperature` | Hot water temperature in Celsius | -| `heat_temperature` | Water Pump heating target temperature in Celsius | -| `heat_min_temperature_value` | Minimum temperature value possible for Water Heater to set | -| `heat_max_temperature_value` | Maximum temperature value possible for Water Heater to set | +| `heat_temperature` | Heat Pump heating target temperature in Celsius | +| `heat_min_temperature_value` | Minimum temperature value possible for Heat Pump to set | +| `heat_max_temperature_value` | Maximum temperature value possible for Heat Pump to set | | `heat_temperature_step` | Step value for temperature setting | -| `operation_mode` | Current operation mode of the Water Heater | -| `available_operation_modes` | List of available operation modes for the Water Heater | +| `operation_mode` | Current operation mode of the Heat Pump | +| `available_operation_modes` | List of available operation modes for the Heat Pump | -## Available functions within ThermiaWaterHeater class: +## Available functions within ThermiaHeatPump class: | Function | Description | | --- | --- | -| `refetch_data` | Refetch all data from Thermia for Water Heater | -| `set_temperature` | Set the target temperature for the Water Heater | -| `set_operation_mode` | Set the operation mode for the Water Heater | \ No newline at end of file +| `refetch_data` | Refetch all data from Thermia for Heat Pump | +| `set_temperature` | Set the target temperature for the Heat Pump | +| `set_operation_mode` | Set the operation mode for the Heat Pump | \ No newline at end of file diff --git a/ThermiaOnlineAPI/__init__.py b/ThermiaOnlineAPI/__init__.py index 309d999..bbc001a 100644 --- a/ThermiaOnlineAPI/__init__.py +++ b/ThermiaOnlineAPI/__init__.py @@ -1,17 +1,17 @@ from ThermiaOnlineAPI.api.ThermiaAPI import ThermiaAPI -from ThermiaOnlineAPI.model.WaterHeater import ThermiaWaterHeater +from ThermiaOnlineAPI.model.HeatPump import ThermiaHeatPump class Thermia(): def __init__(self, username, password): self.api_interface = ThermiaAPI(username, password) self.connected = self.api_interface.authenticated - self.water_heaters = self.__get_water_heaters() + self.heat_pumps = self.__get_heat_pumps() - def __get_water_heaters(self): + def __get_heat_pumps(self): devices = self.api_interface.get_devices() - water_heaters = [] + heat_pumps = [] for device in devices: - water_heaters.append(ThermiaWaterHeater(device, self.api_interface)) + heat_pumps.append(ThermiaHeatPump(device, self.api_interface)) - return water_heaters + return heat_pumps diff --git a/ThermiaOnlineAPI/api/ThermiaAPI.py b/ThermiaOnlineAPI/api/ThermiaAPI.py index e09ca96..9552356 100644 --- a/ThermiaOnlineAPI/api/ThermiaAPI.py +++ b/ThermiaOnlineAPI/api/ThermiaAPI.py @@ -2,7 +2,7 @@ from datetime import datetime import requests -from ..model.WaterHeater import ThermiaWaterHeater +from ..model.HeatPump import ThermiaHeatPump LOGGER = logging.getLogger(__name__) @@ -115,14 +115,14 @@ def get_operation_mode(self, device): return None - def set_temperature(self, device: ThermiaWaterHeater, temperature): + def set_temperature(self, device: ThermiaHeatPump, temperature): self.__set_register_value(device, REGISTER_VALUES["temperature"], temperature) - def set_operation_mode(self, device: ThermiaWaterHeater, mode): + def set_operation_mode(self, device: ThermiaHeatPump, mode): operation_mode_int = device.available_operation_modes.index(mode) self.__set_register_value(device, REGISTER_VALUES["operation_mode"], operation_mode_int) - def __set_register_value(self, device: ThermiaWaterHeater, register_index: REGISTER_VALUES, register_value: int): + def __set_register_value(self, device: ThermiaHeatPump, register_index: REGISTER_VALUES, register_value: int): self.__check_token_validity() url = self.configuration['apiBaseUrl'] + "/api/v1/Registers/Installations/" + str(device.id) + "/Registers" diff --git a/ThermiaOnlineAPI/model/WaterHeater.py b/ThermiaOnlineAPI/model/HeatPump.py similarity index 99% rename from ThermiaOnlineAPI/model/WaterHeater.py rename to ThermiaOnlineAPI/model/HeatPump.py index f4dbb27..83d3076 100644 --- a/ThermiaOnlineAPI/model/WaterHeater.py +++ b/ThermiaOnlineAPI/model/HeatPump.py @@ -8,7 +8,7 @@ LOGGER = logging.getLogger(__name__) -class ThermiaWaterHeater(): +class ThermiaHeatPump(): def __init__(self, device_data: json, api_interface: "ThermiaAPI"): self.__device_data = device_data self.__api_interface = api_interface diff --git a/ThermiaOnlineAPI/model/__init__.py b/ThermiaOnlineAPI/model/__init__.py index 2a3b26c..c5774fe 100644 --- a/ThermiaOnlineAPI/model/__init__.py +++ b/ThermiaOnlineAPI/model/__init__.py @@ -1 +1 @@ -"""Water Heater Model""" +"""Heat Pump Model""" diff --git a/example.py b/example.py index d9d42ca..b433cc1 100644 --- a/example.py +++ b/example.py @@ -7,30 +7,30 @@ print("Connected: " + str(thermia.connected)) -water_heater = thermia.water_heaters[0] - -print("Name: " + water_heater.name) -print("Id: " + str(water_heater.id)) -print("Is Online: " + str(water_heater.is_online)) -print("Last Online: " + str(water_heater.last_online)) -print("Has Indoor Temp Sensor: " + str(water_heater.has_indoor_temp_sensor)) -print("Indoor Temperature: " + str(water_heater.indoor_temperature)) -print("Is Outdoor Temp Sensor Functioning: " + str(water_heater.is_outdoor_temp_sensor_functioning)) -print("Outdoor Temperature: " + str(water_heater.outdoor_temperature)) -print("Is Hot Water Active: " + str(water_heater.is_hot_water_active)) -print("Hot Water Temperature: " + str(water_heater.hot_water_temperature)) -print("Heat Temperature: " + str(water_heater.heat_temperature)) -print("Heat Min Temperature Value: " + str(water_heater.heat_min_temperature_value)) -print("Heat Max Temperature Value: " + str(water_heater.heat_max_temperature_value)) -print("Heat Temperature Step: " + str(water_heater.heat_temperature_step)) -print("Operation Mode: " + str(water_heater.operation_mode)) -print("Available Operation Modes: " + str(water_heater.available_operation_modes)) +heat_pump = thermia.heat_pumps[0] + +print("Name: " + heat_pump.name) +print("Id: " + str(heat_pump.id)) +print("Is Online: " + str(heat_pump.is_online)) +print("Last Online: " + str(heat_pump.last_online)) +print("Has Indoor Temp Sensor: " + str(heat_pump.has_indoor_temp_sensor)) +print("Indoor Temperature: " + str(heat_pump.indoor_temperature)) +print("Is Outdoor Temp Sensor Functioning: " + str(heat_pump.is_outdoor_temp_sensor_functioning)) +print("Outdoor Temperature: " + str(heat_pump.outdoor_temperature)) +print("Is Hot Water Active: " + str(heat_pump.is_hot_water_active)) +print("Hot Water Temperature: " + str(heat_pump.hot_water_temperature)) +print("Heat Temperature: " + str(heat_pump.heat_temperature)) +print("Heat Min Temperature Value: " + str(heat_pump.heat_min_temperature_value)) +print("Heat Max Temperature Value: " + str(heat_pump.heat_max_temperature_value)) +print("Heat Temperature Step: " + str(heat_pump.heat_temperature_step)) +print("Operation Mode: " + str(heat_pump.operation_mode)) +print("Available Operation Modes: " + str(heat_pump.available_operation_modes)) print("\n") -water_heater.set_temperature(19) -water_heater.set_operation_mode("COMPRESSOR") +heat_pump.set_temperature(19) +heat_pump.set_operation_mode("COMPRESSOR") -print("Heat Temperature: " + str(water_heater.heat_temperature)) -print("Operation Mode: " + str(water_heater.operation_mode)) -print("Available Operation Modes: " + str(water_heater.available_operation_modes)) +print("Heat Temperature: " + str(heat_pump.heat_temperature)) +print("Operation Mode: " + str(heat_pump.operation_mode)) +print("Available Operation Modes: " + str(heat_pump.available_operation_modes)) diff --git a/setup.py b/setup.py index ae3f406..9b2486a 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ setup( name='ThermiaOnlineAPI', packages=['ThermiaOnlineAPI', 'ThermiaOnlineAPI.api', 'ThermiaOnlineAPI.model'], - version='1.6', + version='1.7', license='GPL-3.0', description='A Python API for Thermia heat pumps using https://online.thermia.se', long_description=long_description,