Skip to content

Commit

Permalink
Added heat pump operational status data
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Jan 21, 2022
1 parent cdbc378 commit 7ac242a
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/
| `cooling_tank_temperature` | Cooling tank temperature in Celsius |
| `cooling_supply_line_temperature` | Cooling supply line temperature in Celsius |
| --- | --- |
| Operational status | |
| `operational_status` | Operational status of the Heat Pump |
| `available_operational_statuses` | List of available operational statuses |
| `available_operational_statuses_map` | Dictionary mapping operational status names to their values |
| --- | --- |
| Operational Times | |
| `compressor_operational_time` | Compressor operational time in hours |
| `hot_water_operational_time` | Hot water operational time in hours |
Expand Down
50 changes: 50 additions & 0 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from ThermiaOnlineAPI.const import (
REG_GROUP_HOT_WATER,
REG_GROUP_OPERATIONAL_OPERATION,
REG_GROUP_OPERATIONAL_STATUS,
REG_GROUP_OPERATIONAL_TIME,
REG_GROUP_TEMPERATURES,
REGISTER_GROUPS,
Expand Down Expand Up @@ -119,6 +120,55 @@ def get_all_alarms(self, device_id: str):
def get__group_temperatures(self, device_id: str):
return self.__get_register_group(device_id, REG_GROUP_TEMPERATURES)

def get__group_operational_status(self, device_id: str):
register_data = self.__get_register_group(
device_id, REG_GROUP_OPERATIONAL_STATUS
)

data = [
d
for d in register_data
if d["registerName"] == "REG_OPERATIONAL_STATUS_PRIO1"
]

if len(data) != 1:
# Operation operational status not supported
return None

data = data[0]

current_operation_mode_value = int(data.get("registerValue"))
operation_modes_data = data.get("valueNames")

if operation_modes_data is not None:
operation_modes_map = map(
lambda values: {
values.get("value"): values.get("name").split("REG_VALUE_STATUS_")[
1
],
},
operation_modes_data,
)
operation_modes_list = list(operation_modes_map)
operation_modes = ChainMap(*operation_modes_list)

current_operation_mode = [
name
for value, name in operation_modes.items()
if value == current_operation_mode_value
]
if len(current_operation_mode) != 1:
# Something has gone wrong or operation mode not supported
return None

return {
"current": current_operation_mode[0],
"available": operation_modes,
"isReadOnly": data["isReadOnly"],
}

return None

def get__group_operational_time(self, device_id: str):
return self.__get_register_group(device_id, REG_GROUP_OPERATIONAL_TIME)

Expand Down
6 changes: 4 additions & 2 deletions ThermiaOnlineAPI/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
###############################################################################

REG_GROUP_TEMPERATURES = "REG_GROUP_TEMPERATURES"
REG_GROUP_OPERATIONAL_STATUS = "REG_GROUP_OPERATIONAL_STATUS"
REG_GROUP_OPERATIONAL_TIME = "REG_GROUP_OPERATIONAL_TIME"
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,
Expand All @@ -32,8 +34,8 @@
# Temperature registers
###############################################################################

REG_OUTDOOR_TEMPERATURE = "REG_OUTDOOR_TEMPERATURE" # Not used
REG_OPER_DATA_OUTDOOR_TEMP_MA_SA = "REG_OPER_DATA_OUTDOOR_TEMP_MA_SA" # Not used
REG_OUTDOOR_TEMPERATURE = "REG_OUTDOOR_TEMPERATURE" # Not used
REG_OPER_DATA_OUTDOOR_TEMP_MA_SA = "REG_OPER_DATA_OUTDOOR_TEMP_MA_SA" # Not used
REG_INDOOR_TEMPERATURE = "REG_INDOOR_TEMPERATURE"
REG_SUPPLY_LINE = "REG_SUPPLY_LINE"
REG_HOT_WATER_TEMPERATURE = "REG_HOT_WATER_TEMPERATURE"
Expand Down
24 changes: 24 additions & 0 deletions ThermiaOnlineAPI/model/HeatPump.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, device_data: json, api_interface: "ThermiaAPI"):

# GROUPS
self.__group_temperatures = None
self.__group_operational_status = None
self.__group_operational_time = None
self.__group_operational_operation = None
self.__group_hot_water = None
Expand All @@ -71,6 +72,9 @@ def update_data(self):
self.__group_temperatures = self.__api_interface.get__group_temperatures(
self.__device_id
)
self.__group_operational_status = (
self.__api_interface.get__group_operational_status(self.__device_id)
)
self.__group_operational_time = (
self.__api_interface.get__group_operational_time(self.__device_id)
)
Expand Down Expand Up @@ -322,6 +326,26 @@ def cooling_supply_line_temperature(self):
"value",
)

###########################################################################
# Operational status data
###########################################################################

@property
def operational_status(self):
return get_dict_value_safe(self.__group_operational_status, "current")

@property
def available_operational_statuses(self):
return list(
get_dict_value_safe(
self.__group_operational_status, "available", {}
).values()
)

@property
def available_operational_statuses_map(self):
return get_dict_value_safe(self.__group_operational_status, "available", {})

###########################################################################
# Operational time data
###########################################################################
Expand Down
12 changes: 12 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@

print("\n")

print("Operational status")
print("Operational status: " + str(heat_pump.operational_status))
print(
"Available operational statuses: " + str(heat_pump.available_operational_statuses)
)
print(
"Available operational statuses map: "
+ str(heat_pump.available_operational_statuses_map)
)

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))
Expand Down

0 comments on commit 7ac242a

Please sign in to comment.