Skip to content

Commit

Permalink
Active alarm bug fixes, added active alarm titles list
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Jan 14, 2022
1 parent d74ae1e commit 9ed0369
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
| `available_operation_modes` | List of available operation modes for the Heat Pump |
| `is_hot_water_switch_available` | Boolean value indicating if the Heat Pump has a hot water switch |
| `active_alarm_count` | Number of active alarms on the Heat Pump |
| `active_alarms` | List of titles of active alarms on the Heat Pump |

## Available functions within ThermiaHeatPump class:
| Function | Description |
Expand Down
18 changes: 18 additions & 0 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ def get_device_status(self, device_id: str):

return request.json()

def get_all_alarms(self, device_id: str):
self.__check_token_validity()

url = (
self.configuration["apiBaseUrl"]
+ "/api/v1/installation/"
+ str(device_id)
+ "/events?onlyActiveAlarms=false"
)
request = requests.get(url, headers=self.__default_request_headers)
status = request.status_code

if status != 200:
_LOGGER.error("Error in getting device's alarms. " + str(status))
return None

return request.json()

def get_temperature_status(self, device: ThermiaHeatPump):
self.__check_token_validity()

Expand Down
19 changes: 18 additions & 1 deletion ThermiaOnlineAPI/model/HeatPump.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def __init__(self, device_data: json, api_interface: "ThermiaAPI"):
self.__operation_mode_state = None
self.__hot_water_switch_state = None

self.__alarms = None

self.__register_indexes = DEFAULT_REGISTER_INDEXES

self.update_data()
Expand All @@ -47,6 +49,8 @@ def update_data(self):
self
)

self.__alarms = self.__api_interface.get_all_alarms(self.__device_id)

def get_register_indexes(self):
return self.__register_indexes

Expand Down Expand Up @@ -86,6 +90,12 @@ def set_hot_water_switch_state(self, state: int):
self.__api_interface.set_hot_water_switch_state(self, state)
self.update_data()

def __get_active_alarms(self):
active_alarms = filter(
lambda alarm: alarm.get("isActiveAlarm", False) is True, self.__alarms
)
return list(active_alarms)

@property
def name(self):
return self.__info.get("name")
Expand Down Expand Up @@ -177,4 +187,11 @@ def hot_water_switch_state(self):

@property
def active_alarm_count(self):
return self.__device_data.get("status", {}).get("activeAlarms", None)
active_alarms = self.__get_active_alarms()
return len(list(active_alarms))

@property
def active_alarms(self):
active_alarms = self.__get_active_alarms()
active_alarm_texts = map(lambda alarm: alarm.get("eventTitle"), active_alarms)
return list(active_alarm_texts)
2 changes: 2 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
print("Heat Max Temperature Value: " + str(heat_pump.heat_max_temperature_value))
print("Heat Temperature Step: " + str(heat_pump.heat_temperature_step))
print("Active Alarm Count: " + str(heat_pump.active_alarm_count))
if heat_pump.active_alarm_count > 0:
print("Active Alarms: " + str(heat_pump.active_alarms))

print("\n")

Expand Down

0 comments on commit 9ed0369

Please sign in to comment.