Skip to content

Commit

Permalink
Add debug function, update Readme about it
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Jun 27, 2022
1 parent 2fa200a commit 4ca7621
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 65 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ __pycache__/
# PyPi
MANIFEST
build/
dist/
dist/

# Debug file
debug.txt
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
## Confirmed Thermia models that API supports:
* Danfoss DHP-AQ 9

## Regarding unsupported models
I am willing to do my best to support them, but as there turns out to be many different Thermia models and configurations, it is hard for me to implement all functionalities and test them thoroughly.
Thus, I have created a `debug()` function that runs when `example.py` is executed and creates a `debug.txt` file which has data about your heat pump and all its supported features. If you want to submit a bug or feature request, please include the debug file as it will make my development much easier.

**Note:** I have done my best to remove the sensitive parts from debugging, but I do not guarantee that no sensitive data is printed to the debug file. I have no intention of using it maliciously, but if you post the file publicly on GitHub, please make sure you remove anything you feel might be suspicious of sharing.

## Supported APIs:
* `classic`, default, online access url is https://online.thermia.se
* `genesis`, online access url is https://online-genesis.thermia.se
Expand All @@ -18,8 +24,8 @@ See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/
## Available functions in Thermia class:
| Function | Description |
| --- | --- |
| `fetch_heat_pumps` | Fetches all heat pumps from Thermia Online API and their data |
| `update_data` | Updates all heat pump data |
| `fetch_heat_pumps()` | Fetches all heat pumps from Thermia Online API and their data |
| `update_data()` | Updates all heat pump data |

## Available properties within ThermiaHeatPump class:
| Property | Description |
Expand Down Expand Up @@ -80,12 +86,15 @@ See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/
## Available functions within ThermiaHeatPump class:
| Function | Description |
| --- | --- |
| `update_data` | Refetch all data from Thermia for Heat Pump |
| `update_data()` | Refetch all data from Thermia for Heat Pump |
| --- | --- |
| 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 |
| `set_hot_water_switch_state` | Set the hot water switch state to 0 (off) or 1 (on) for the Heat Pump |
| `set_temperature()` | Set the target temperature for the Heat Pump |
| `set_operation_mode()` | Set the operation mode for the Heat Pump |
| `set_hot_water_switch_state()` | Set the hot water switch state to 0 (off) or 1 (on) for the Heat Pump |
| --- | --- |
| Fetch historical data | |
| `get_historical_data_for_register` | Fetch historical data by using register name from `historical_data_registers` together with start_time and end_time of the data in Python datatime format. Returns list of dictionaries which contains data in format `{ "time": datetime, "value": int }` |
| `get_historical_data_for_register()` | Fetch historical data by using register name from `historical_data_registers` together with start_time and end_time of the data in Python datatime format. Returns list of dictionaries which contains data in format `{ "time": datetime, "value": int }` |
| --- | --- |
| Fetch debug data | |
| `debug()` | Fetch debug data from Thermia API and save it to `debug.txt` file |
46 changes: 37 additions & 9 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def __init__(self, email, password, api_type):
def get_devices(self):
self.__check_token_validity()

url = self.configuration["apiBaseUrl"] + "/api/v1/InstallationsInfo/own"
url = self.configuration["apiBaseUrl"] + \
"/api/v1/InstallationsInfo/own"
request = requests.get(url, headers=self.__default_request_headers)
status = request.status_code

Expand All @@ -71,7 +72,8 @@ def get_device_by_id(self, device_id: str):
def get_device_info(self, device_id: str):
self.__check_token_validity()

url = self.configuration["apiBaseUrl"] + "/api/v1/installations/" + device_id
url = self.configuration["apiBaseUrl"] + \
"/api/v1/installations/" + device_id
request = requests.get(url, headers=self.__default_request_headers)
status = request.status_code

Expand Down Expand Up @@ -155,12 +157,29 @@ def get_historical_data(

if status != 200:
_LOGGER.error(
"Error in historical data for specific register. " + str(status)
"Error in historical data for specific register. " +
str(status)
)
return None

return request.json()

def get_all_available_groups(self, installation_profile_id: int):
self.__check_token_validity()

url = self.configuration["apiBaseUrl"] + \
"/api/v1/installationprofiles/" + \
str(installation_profile_id) + "/groups"

request = requests.get(url, headers=self.__default_request_headers)
status = request.status_code

if status != 200:
_LOGGER.error("Error in getting available groups. " + str(status))
return None

return request.json()

def get__group_temperatures(self, device_id: str):
return self.__get_register_group(device_id, REG_GROUP_TEMPERATURES)

Expand Down Expand Up @@ -221,7 +240,8 @@ def get_group_operational_operation(self, device: ThermiaHeatPump):
device.id, REG_GROUP_OPERATIONAL_OPERATION
)

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

if len(data) != 1:
# Operation mode not supported
Expand Down Expand Up @@ -264,9 +284,11 @@ def get_group_operational_operation(self, device: ThermiaHeatPump):
return None

def get_group_hot_water(self, device: ThermiaHeatPump):
register_data = self.__get_register_group(device.id, REG_GROUP_HOT_WATER)
register_data = self.__get_register_group(
device.id, REG_GROUP_HOT_WATER)

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

if len(data) == 0:
# Hot water switch not supported
Expand All @@ -285,7 +307,8 @@ def get_group_hot_water(self, device: ThermiaHeatPump):
return None

def set_temperature(self, device: ThermiaHeatPump, temperature):
device_temperature_register_index = device.get_register_indexes()["temperature"]
device_temperature_register_index = device.get_register_indexes()[
"temperature"]
if device_temperature_register_index is None:
_LOGGER.error(
"Error setting device's temperature. No temperature register index."
Expand Down Expand Up @@ -344,6 +367,9 @@ def set_hot_water_switch_state(
device, device_hot_water_switch_state_register_index, 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):
self.__check_token_validity()

Expand Down Expand Up @@ -385,7 +411,8 @@ def __set_register_value(
"clientUuid": "api-client-uuid",
}

request = requests.post(url, headers=self.__default_request_headers, json=body)
request = requests.post(
url, headers=self.__default_request_headers, json=body)

status = request.status_code
if status != 200:
Expand Down Expand Up @@ -429,7 +456,8 @@ def __authenticate(self):
auth_data = request_auth.json()

token_valid_to = auth_data.get("tokenValidToUtc").split(".")[0]
datetime_object = datetime.strptime(token_valid_to, "%Y-%m-%dT%H:%M:%S")
datetime_object = datetime.strptime(
token_valid_to, "%Y-%m-%dT%H:%M:%S")
token_valid_to = datetime_object.timestamp()

self.__token = auth_data.get("token")
Expand Down
Loading

0 comments on commit 4ca7621

Please sign in to comment.