Skip to content

Commit

Permalink
Thermia Genesis API support
Browse files Browse the repository at this point in the history
  • Loading branch information
klejejs committed Jan 18, 2022
1 parent d47ddc0 commit 40eae74
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 11 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ Platform | Description

To set up Thermia Heat Pump Integration, go to Settings -> Integrations -> Add Integration and search for Thermia Heat Pump.

Depending on the url you use to see your heat pump online, you need to choose the following API type:
* `classic` - for url: https://online.thermia.se
* `genesis` - for url: https://online-genesis.thermia.se

## Installation

Open HACS, go to the Integrations view and search for Thermia Heat Pump Integration.
Expand Down
7 changes: 5 additions & 2 deletions custom_components/thermia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ThermiaOnlineAPI import Thermia
from ThermiaOnlineAPI.api.ThermiaAPI import ThermiaAPI

from .const import CONF_PASSWORD, CONF_USERNAME, DOMAIN
from .const import API_TYPE, API_TYPE_CLASSIC, CONF_PASSWORD, CONF_USERNAME, DOMAIN

PLATFORMS: list[str] = ["sensor", "switch", "water_heater"]

Expand All @@ -30,8 +30,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):

username = config_entry.data[CONF_USERNAME]
password = config_entry.data[CONF_PASSWORD]
api_type = config_entry.data.get(API_TYPE, API_TYPE_CLASSIC)

thermia = await hass.async_add_executor_job(lambda: Thermia(username, password))
thermia = await hass.async_add_executor_job(
lambda: Thermia(username, password, api_type)
)

coordinator = ThermiaDataUpdateCoordinator(hass, thermia)

Expand Down
25 changes: 19 additions & 6 deletions custom_components/thermia/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
"""Config Flow for Thermia."""
import logging

import voluptuous as vol

import homeassistant.helpers.config_validation as cv
from homeassistant import config_entries
from ThermiaOnlineAPI import AuthenticationException, Thermia
from voluptuous import Required, Schema

from .const import CONF_PASSWORD, CONF_USERNAME, DOMAIN
from .const import (
API_TYPE,
API_TYPE_CLASSIC,
API_TYPES,
CONF_PASSWORD,
CONF_USERNAME,
DOMAIN,
)

STEP_USER_DATA_SCHEMA = Schema(
STEP_USER_DATA_SCHEMA = vol.Schema(
{
Required(CONF_USERNAME): cv.string,
Required(CONF_PASSWORD): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Required(API_TYPE, default=API_TYPE_CLASSIC): vol.In(API_TYPES),
}
)

Expand All @@ -32,7 +41,11 @@ async def _check_credentials(self, user_input):
"""Check if Thermia credentials are valid."""
try:
thermia = await self.hass.async_add_executor_job(
lambda: Thermia(user_input[CONF_USERNAME], user_input[CONF_PASSWORD])
lambda: Thermia(
user_input[CONF_USERNAME],
user_input[CONF_PASSWORD],
user_input[API_TYPE],
)
)
await self.hass.async_add_executor_job(thermia.fetch_heat_pumps)
except Exception as error:
Expand Down
6 changes: 6 additions & 0 deletions custom_components/thermia/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@

CONF_USERNAME = "username"
CONF_PASSWORD = "password"

API_TYPE_CLASSIC = "classic"
API_TYPE_GENESIS = "genesis"

API_TYPE = "api_type"
API_TYPES = [API_TYPE_CLASSIC, API_TYPE_GENESIS]
2 changes: 1 addition & 1 deletion custom_components/thermia/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@klejejs"
],
"requirements": [
"ThermiaOnlineAPI==2.6"
"ThermiaOnlineAPI==2.7"
],
"version": "1.0",
"iot_class": "cloud_polling",
Expand Down
3 changes: 2 additions & 1 deletion custom_components/thermia/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"description": "Set up Thermia Heat Pump integration",
"data": {
"username": "Thermia Username",
"password": "Thermia Password"
"password": "Thermia Password",
"api_type": "API type (check readme for more info):"
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "Thermia Heat Pump",
"render_readme": true,
"domains": ["sensor", "water_heater"]
"domains": ["sensor", "switch", "water_heater"]
}

0 comments on commit 40eae74

Please sign in to comment.