Skip to content

Commit

Permalink
Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Dec 26, 2021
1 parent 38e2a84 commit 7159c0c
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 53 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 |
| `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 |
12 changes: 6 additions & 6 deletions ThermiaOnlineAPI/__init__.py
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime
import requests

from ..model.WaterHeater import ThermiaWaterHeater
from ..model.HeatPump import ThermiaHeatPump

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ThermiaOnlineAPI/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"""Water Heater Model"""
"""Heat Pump Model"""
46 changes: 23 additions & 23 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
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(
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,
Expand Down

0 comments on commit 7159c0c

Please sign in to comment.