Skip to content

Commit

Permalink
Merge pull request #11 from klejejs/feature/add-generic-register-gett…
Browse files Browse the repository at this point in the history
…er-and-setter-functions

Add generic register getter and setter functions
  • Loading branch information
klejejs authored Nov 22, 2022
2 parents f85b21f + 956130e commit 3d9e49e
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 30 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/
| --- | --- |
| `update_data()` | Refetch all data from Thermia for Heat Pump |
| --- | --- |
| `get_all_available_register_groups()` | Return a list of all available register groups for the heat pump |
| `get_available_registers_for_group(register_group)` | Return a list of all available registers for specified register group |
| `get_register_data_by_register_group_and_name(register_group, register_name)` | Return data for specified register group and name |
| `set_register_data_by_register_group_and_name(register_group, register_name, value)` | Set register value for specified register group and name |
| --- | --- |
| Change heat pump state | |
| `set_temperature()` | Set the target temperature for the Heat Pump |
| `set_operation_mode()` | Set the operation mode for the Heat Pump |
Expand Down
9 changes: 6 additions & 3 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from collections import ChainMap
from datetime import datetime, timedelta
import requests
import urllib.parse
import json
import hashlib

Expand All @@ -12,7 +11,6 @@
REG_GROUP_OPERATIONAL_STATUS,
REG_GROUP_OPERATIONAL_TIME,
REG_GROUP_TEMPERATURES,
REGISTER_GROUPS,
THERMIA_API_CONFIG_URLS_BY_API_TYPE,
THERMIA_API_TYPE_CLASSIC,
THERMIA_AZURE_AUTH_URL,
Expand Down Expand Up @@ -377,7 +375,12 @@ def set_hot_water_switch_state(
def get_register_group_json(self, device_id: str, register_group):
return self.__get_register_group(device_id, register_group)

def __get_register_group(self, device_id: str, register_group: REGISTER_GROUPS):
def set_register_value(
self, device: ThermiaHeatPump, register_index: int, value: int
):
self.__set_register_value(device, register_index, value)

def __get_register_group(self, device_id: str, register_group: str):
self.__check_token_validity()

url = (
Expand Down
8 changes: 0 additions & 8 deletions ThermiaOnlineAPI/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,6 @@
REG_GROUP_OPERATIONAL_OPERATION = "REG_GROUP_OPERATIONAL_OPERATION"
REG_GROUP_HOT_WATER = "REG_GROUP_HOT_WATER"

REGISTER_GROUPS = [
REG_GROUP_TEMPERATURES,
REG_GROUP_OPERATIONAL_STATUS,
REG_GROUP_OPERATIONAL_TIME,
REG_GROUP_OPERATIONAL_OPERATION,
REG_GROUP_HOT_WATER,
]

###############################################################################
# Temperature registers
###############################################################################
Expand Down
59 changes: 58 additions & 1 deletion ThermiaOnlineAPI/model/HeatPump.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,61 @@ def set_hot_water_switch_state(self, state: int):
self.__api_interface.set_hot_water_switch_state(self, state)
self.update_data()

def get_all_available_register_groups(self):
installation_profile_id = self.__info.get("installationProfileId")
register_groups = self.__api_interface.get_all_available_groups(
installation_profile_id
)

if register_groups is None:
return []

return list(map(lambda x: x["name"], register_groups))

def get_available_registers_for_group(self, register_group: str):
registers_for_group = self.__api_interface.get_register_group_json(
self.__device_id, register_group
)

if registers_for_group is None:
return []

return list(map(lambda x: x["registerName"], registers_for_group))

def get_register_data_by_register_group_and_name(
self, register_group: str, register_name: str
):
register_group = self.__api_interface.get_register_group_json(
self.__device_id, register_group
)

if register_group is None:
self._LOGGER.error("No register group found for group: " + register_group)
return None

return self.__get_data_from_group_by_register_name(
register_group, register_name
)

def set_register_data_by_register_group_and_name(
self, register_group: str, register_name: str, value: int
):
register_data = self.get_register_data_by_register_group_and_name(
register_group, register_name
)

if register_data is None:
self._LOGGER.error(
"No register group found for group: "
+ register_group
+ " and register: "
+ register_name
)
return None

self.__api_interface.set_register_value(self, register_data["id"], value)
self.update_data()

def __get_heat_temperature_data(self):
device_temperature_register_index = self.get_register_indexes()["temperature"]
if device_temperature_register_index is None:
Expand Down Expand Up @@ -176,12 +231,14 @@ def __get_data_from_group_by_register_name(self, group, register_name: str):
data = [d for d in group if d["registerName"] == register_name]

if len(data) != 1:
# Temperature status not supported
# Register not in the group
return None

data = data[0]

return {
"id": data["registerIndex"],
"isReadOnly": data["isReadOnly"],
"minValue": data["minValue"],
"maxValue": data["maxValue"],
"step": data["step"],
Expand Down
53 changes: 35 additions & 18 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,37 @@

print("\n")

print(
"All available register groups: "
+ str(heat_pump.get_all_available_register_groups())
)

print(
"Available registers for 'REG_GROUP_HEATING_CURVE' group: "
+ str(heat_pump.get_available_registers_for_group("REG_GROUP_HEATING_CURVE"))
)

print("\n")

print("Other temperatures")
print("Supply Line Temperature: " + str(heat_pump.supply_line_temperature))
print(
"Desired Supply Line Temperature: " +
str(heat_pump.desired_supply_line_temperature)
"Desired Supply Line Temperature: " + str(heat_pump.desired_supply_line_temperature)
)
print("Return Line Temperature: " + str(heat_pump.return_line_temperature))
print("Brine Out Temperature: " + str(heat_pump.brine_out_temperature))
print("Brine In Temperature: " + str(heat_pump.brine_in_temperature))
print("Cooling Tank Temperature: " + str(heat_pump.cooling_tank_temperature))
print(
"Cooling Supply Line Temperature: " +
str(heat_pump.cooling_supply_line_temperature)
"Cooling Supply Line Temperature: " + str(heat_pump.cooling_supply_line_temperature)
)

print("\n")

print("Operational status")
print("Operational status: " + str(heat_pump.operational_status))
print(
"Available operational statuses: " +
str(heat_pump.available_operational_statuses)
"Available operational statuses: " + str(heat_pump.available_operational_statuses)
)
print(
"Available operational statuses map: "
Expand All @@ -47,10 +56,8 @@
print("\n")

print("Operational Times")
print("Compressor Operational Time: " +
str(heat_pump.compressor_operational_time))
print("Hot Water Operational Time: " +
str(heat_pump.hot_water_operational_time))
print("Compressor Operational Time: " + str(heat_pump.compressor_operational_time))
print("Hot Water Operational Time: " + str(heat_pump.hot_water_operational_time))
print(
"Auxiliary Heater 1 Operational Time: "
+ str(heat_pump.auxiliary_heater_1_operational_time)
Expand All @@ -76,24 +83,20 @@
print("Operation Mode data")
print("Operation Mode: " + str(heat_pump.operation_mode))
print("Available Operation Modes: " + str(heat_pump.available_operation_modes))
print("Available Operation Modes Map: " +
str(heat_pump.available_operation_mode_map))
print("Is Operation Mode Read Only: " +
str(heat_pump.is_operation_mode_read_only))
print("Available Operation Modes Map: " + str(heat_pump.available_operation_mode_map))
print("Is Operation Mode Read Only: " + str(heat_pump.is_operation_mode_read_only))

print("\n")

print("Hot Water data")
print("Is Hot Water Switch Available: " +
str(heat_pump.is_hot_water_switch_available))
print("Is Hot Water Switch Available: " + str(heat_pump.is_hot_water_switch_available))
if heat_pump.is_hot_water_switch_available:
print("Hot Water Switch State: " + str(heat_pump.hot_water_switch_state))

print("\n")

print(
"Available historical data registers: " +
str(heat_pump.historical_data_registers)
"Available historical data registers: " + str(heat_pump.historical_data_registers)
)
print(
"Historical data for outdoor temperature during past 24h: "
Expand All @@ -108,9 +111,23 @@

print("\n")

print(
"Heating Curve Register Data: "
+ str(
heat_pump.get_register_data_by_register_group_and_name(
"REG_GROUP_HEATING_CURVE", "REG_HEATING_HEAT_CURVE"
)
)
)

print("\n")

thermia.update_data()

heat_pump.set_temperature(19)
heat_pump.set_register_data_by_register_group_and_name(
"REG_GROUP_HEATING_CURVE", "REG_HEATING_HEAT_CURVE", 30
)
heat_pump.set_operation_mode("COMPRESSOR")
if heat_pump.is_hot_water_switch_available:
heat_pump.set_hot_water_switch_state(1)
Expand Down

0 comments on commit 3d9e49e

Please sign in to comment.