Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ Thus, I have created a `debug()` function that runs when `example.py` is execute

**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

## How to use api:
See [example.py](https://github.com/klejejs/python-thermia-online-api/blob/main/example.py) file for examples.

Expand Down
5 changes: 2 additions & 3 deletions ThermiaOnlineAPI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from ThermiaOnlineAPI.api.ThermiaAPI import ThermiaAPI
from ThermiaOnlineAPI.exceptions import AuthenticationException, NetworkException
from ThermiaOnlineAPI.model.HeatPump import ThermiaHeatPump
from ThermiaOnlineAPI.const import THERMIA_API_TYPE_CLASSIC


class Thermia:
def __init__(self, username, password, api_type=THERMIA_API_TYPE_CLASSIC):
def __init__(self, username, password):
self._username = username
self._password = password

self.api_interface = ThermiaAPI(username, password, api_type)
self.api_interface = ThermiaAPI(username, password)
self.connected = self.api_interface.authenticated

self.heat_pumps = self.fetch_heat_pumps()
Expand Down
11 changes: 3 additions & 8 deletions ThermiaOnlineAPI/api/ThermiaAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
REG_HOT_WATER_STATUS,
REG__HOT_WATER_BOOST,
REG_OPERATIONMODE,
THERMIA_API_CONFIG_URLS_BY_API_TYPE,
THERMIA_CONFIG_URL,
THERMIA_AZURE_AUTH_URL,
THERMIA_AZURE_AUTH_CLIENT_ID_AND_SCOPE,
THERMIA_AZURE_AUTH_REDIRECT_URI,
Expand Down Expand Up @@ -47,7 +47,7 @@


class ThermiaAPI:
def __init__(self, email, password, api_type):
def __init__(self, email, password):
self.__email = email
self.__password = password
self.__token = None
Expand All @@ -69,11 +69,6 @@ def __init__(self, email, password, api_type):
adapter = HTTPAdapter(max_retries=retry)
self.__session.mount("https://", adapter)

if api_type not in THERMIA_API_CONFIG_URLS_BY_API_TYPE:
raise ValueError("Unknown device type: " + api_type)

self.__api_config_url = THERMIA_API_CONFIG_URLS_BY_API_TYPE[api_type]

self.configuration = self.__fetch_configuration()
self.authenticated = self.__authenticate()

Expand Down Expand Up @@ -514,7 +509,7 @@ def __set_register_value(
)

def __fetch_configuration(self):
request = self.__session.get(self.__api_config_url)
request = self.__session.get(THERMIA_CONFIG_URL)
status = request.status_code

if status != 200:
Expand Down
14 changes: 2 additions & 12 deletions ThermiaOnlineAPI/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@
# General configuration
###############################################################################

THERMIA_CLASSIC_API_CONFIG_URL = "https://online.thermia.se/api/configuration"
THERMIA_GENESIS_API_CONFIG_URL = "https://online-genesis.thermia.se/api/configuration"

THERMIA_CONFIG_URL = "https://online.thermia.se/api/configuration"
THERMIA_INSTALLATION_PATH = "/api/v1/Registers/Installations/"

THERMIA_API_TYPE_CLASSIC = "classic"
THERMIA_API_TYPE_GENESIS = "genesis"

THERMIA_API_CONFIG_URLS_BY_API_TYPE = {
THERMIA_API_TYPE_CLASSIC: THERMIA_CLASSIC_API_CONFIG_URL,
THERMIA_API_TYPE_GENESIS: THERMIA_GENESIS_API_CONFIG_URL,
}

###############################################################################
# Azure AD configuration
###############################################################################

THERMIA_AZURE_AUTH_URL = "https://thermialogin.b2clogin.com/thermialogin.onmicrosoft.com/b2c_1a_signuporsigninonline"
THERMIA_AZURE_AUTH_CLIENT_ID_AND_SCOPE = "09ea4903-9e95-45fe-ae1f-e3b7d32fa385"
THERMIA_AZURE_AUTH_REDIRECT_URI = "https://online-genesis.thermia.se/login"
THERMIA_AZURE_AUTH_REDIRECT_URI = "https://online.thermia.se/login"

###############################################################################
# Register groups
Expand Down
1 change: 0 additions & 1 deletion credentials.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
USERNAME = ""
PASSWORD = ""
API_TYPE = "" # classic or genesis
18 changes: 2 additions & 16 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from datetime import datetime, timedelta
from ThermiaOnlineAPI import Thermia
from credentials import USERNAME, PASSWORD, API_TYPE
from ThermiaOnlineAPI.const import (
THERMIA_API_TYPE_CLASSIC,
THERMIA_API_TYPE_GENESIS,
)
from credentials import USERNAME, PASSWORD

CHANGE_HEAT_PUMP_DATA_DURING_TEST = (
False # Set to True if you want to change heat pump data during test
Expand All @@ -14,17 +10,7 @@
USERNAME = input("Enter username: ")
PASSWORD = input("Enter password: ")

if not API_TYPE:
api_type_number = input("Enter api type (1 = classic, 2 = genesis): ")
if api_type_number == "1":
API_TYPE = THERMIA_API_TYPE_CLASSIC
elif api_type_number == "2":
API_TYPE = THERMIA_API_TYPE_GENESIS
else:
print("Invalid api type")
exit(1)

thermia = Thermia(USERNAME, PASSWORD, api_type=API_TYPE)
thermia = Thermia(USERNAME, PASSWORD)

print("Connected: " + str(thermia.connected))

Expand Down