Skip to content

Commit

Permalink
adding (again) option to specify an alternative username (!='waterkot…
Browse files Browse the repository at this point in the history
…te')

2024.10.1
  • Loading branch information
marq24 committed Oct 16, 2024
1 parent ae38cb4 commit 95b024f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions custom_components/waterkotte_heatpump/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from datetime import timedelta
from typing import List, Collection, Sequence, Any, Tuple
from homeassistant.const import CONF_ID, CONF_HOST, CONF_PASSWORD
from homeassistant.const import CONF_ID, CONF_HOST, CONF_USERNAME, CONF_PASSWORD
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
from homeassistant.core import Config, SupportsResponse, Event
from homeassistant.core import HomeAssistant
Expand Down Expand Up @@ -169,13 +169,13 @@ def __init__(self, hass: HomeAssistant, config_entry):
_LOGGER.debug(f"available_features: {self.available_features}")

_host = config_entry.options.get(CONF_HOST, config_entry.data.get(CONF_HOST))
# _user = config_entry.options.get(CONF_USERNAME, config_entry.data.get(CONF_USERNAME, "waterkotte"))
_user = config_entry.options.get(CONF_USERNAME, config_entry.data.get(CONF_USERNAME, "waterkotte"))
_pwd = config_entry.options.get(CONF_PASSWORD, config_entry.data.get(CONF_PASSWORD, "waterkotte"))
_system_type = config_entry.options.get(CONF_SYSTEMTYPE, config_entry.data.get(CONF_SYSTEMTYPE, ECOTOUCH))
_tags_num = config_entry.options.get(CONF_TAGS_PER_REQUEST, config_entry.data.get(CONF_TAGS_PER_REQUEST, 10))
_tags = generate_tag_list(hass=hass, trim_unique_id=self.is_multi_instances, config_entry_id=config_entry.entry_id)

self.bridge = WaterkotteClient(host=_host, pwd=_pwd, system_type=_system_type,
self.bridge = WaterkotteClient(host=_host, username=_user, pwd=_pwd, system_type=_system_type,
web_session=async_get_clientsession(hass), tags=_tags,
tags_per_request=_tags_num, lang=hass.config.language.lower())

Expand Down
12 changes: 8 additions & 4 deletions custom_components/waterkotte_heatpump/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ async def async_step_user_easycon(self, user_input=None):
user_input[CONF_ADD_SCHEDULE_ENTITIES] = False
valid = await self._test_credentials(
host=user_input[CONF_HOST],
username=None,
pwd=None,
system_type=user_input[CONF_SYSTEMTYPE],
tags_per_request=user_input[CONF_TAGS_PER_REQUEST],
Expand Down Expand Up @@ -143,6 +144,7 @@ async def async_step_user_ecotouch(self, user_input=None):
user_input[CONF_SYSTEMTYPE] = ECOTOUCH
valid = await self._test_credentials(
host=user_input[CONF_HOST],
username=user_input[CONF_USERNAME],
pwd=user_input[CONF_PASSWORD],
system_type=user_input[CONF_SYSTEMTYPE],
tags_per_request=user_input[CONF_TAGS_PER_REQUEST],
Expand All @@ -160,6 +162,7 @@ async def async_step_user_ecotouch(self, user_input=None):
else:
user_input = {}
user_input[CONF_HOST] = ""
user_input[CONF_USERNAME] = "waterkotte"
user_input[CONF_PASSWORD] = "waterkotte"
user_input[CONF_ADD_SCHEDULE_ENTITIES] = False
user_input[CONF_ADD_SERIAL_AS_ID] = False
Expand All @@ -168,6 +171,7 @@ async def async_step_user_ecotouch(self, user_input=None):
step_id="user_ecotouch",
data_schema=vol.Schema({
vol.Required(CONF_HOST, default=user_input.get(CONF_HOST)): str,
vol.Optional(CONF_USERNAME, default=user_input.get(CONF_USERNAME)): str,
vol.Required(CONF_PASSWORD, default=user_input.get(CONF_PASSWORD)): str,
vol.Required(CONF_POLLING_INTERVAL, default=60): int,
vol.Required(CONF_TAGS_PER_REQUEST, default=75): int,
Expand Down Expand Up @@ -198,11 +202,11 @@ async def async_step_features(self, user_input=None):
errors=self._errors
)

async def _test_credentials(self, host, pwd, system_type, tags_per_request):
async def _test_credentials(self, host, username, pwd, system_type, tags_per_request):
try:
session = async_create_clientsession(self.hass)
client = WaterkotteClient(host=host, pwd=pwd, system_type=system_type, web_session=session,
tags=None, tags_per_request=tags_per_request,
client = WaterkotteClient(host=host, username=username, pwd=pwd, system_type=system_type,
web_session=session, tags=None, tags_per_request=tags_per_request,
lang=self.hass.config.language.lower())
await client.login()
init_tags = [
Expand Down Expand Up @@ -260,7 +264,7 @@ async def async_step_user(self, user_input=None):
return self.async_show_form(
step_id="user",
data_schema=vol.Schema({
# vol.Required(CONF_USERNAME, default=self.options.get(CONF_USERNAME, "waterkotte")): str,
vol.Optional(CONF_USERNAME, default=self.options.get(CONF_USERNAME, "waterkotte")): str,
vol.Required(CONF_PASSWORD, default=self.options.get(CONF_PASSWORD, "waterkotte")): str,
vol.Required(CONF_POLLING_INTERVAL, default=self.options.get(CONF_POLLING_INTERVAL, 60)): int,
vol.Required(CONF_TAGS_PER_REQUEST, default=self.options.get(CONF_TAGS_PER_REQUEST, 75)): int,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/waterkotte_heatpump/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-waterkotte/issues",
"requirements": [],
"version": "2024.10.0"
"version": "2024.10.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@


class WaterkotteClient:
def __init__(self, host: str, pwd: str, system_type: str, web_session, tags: list, tags_per_request: int,
lang: str = "en") -> None:
def __init__(self, host: str, username: str, pwd: str, system_type: str, web_session,
tags: list, tags_per_request: int, lang: str = "en") -> None:
self._host = host
self._systemType = system_type
if system_type == ECOTOUCH:
self._internal_client = EcotouchBridge(host=host, web_session=web_session, pwd=pwd,
tags_per_request=tags_per_request, lang=lang)
self._internal_client = EcotouchBridge(host=host, web_session=web_session, username=username,
pwd=pwd, tags_per_request=tags_per_request, lang=lang)
elif system_type == EASYCON:
self._internal_client = EasyconBridge(host=host, web_session=web_session)
else:
Expand Down Expand Up @@ -104,8 +104,9 @@ async def async_write_values(self, kv_pairs: Collection[Tuple[WKHPTag, Any]]):
class EcotouchBridge:
auth_cookies = None

def __init__(self, host: str, web_session, pwd: str = "waterkotte", tags_per_request: int = 10, lang: str = "en"):
def __init__(self, host: str, web_session, username: str ="waterkotte", pwd: str = "waterkotte", tags_per_request: int = 10, lang: str = "en"):
self.host = host
self.username = username
self.pwd = pwd
self.web_session = web_session
self.tags_per_request = min(tags_per_request, 75)
Expand Down Expand Up @@ -137,7 +138,7 @@ async def login(self):
_LOGGER.info(f"login to waterkotte host {self.host}")

# it's only possible to adjust the password of the 'waterkotte' build in user
args = {"username": "waterkotte", "password": self.pwd}
args = {"username": self.username, "password": self.pwd}

async with self.web_session.get(f"http://{self.host}/cgi/login", params=args) as response:
response.raise_for_status()
Expand Down
6 changes: 3 additions & 3 deletions custom_components/waterkotte_heatpump/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"description": "Wichtiger Hinweis: Mit dem 'Zeitprogramm anpassen Service' kannst Du alle Zeitpläne Deiner Waterkotte Wärmepumpe anpassen. Das Hinzufügen der optionalen Entitäten ist hierfür nicht notwendig. Diese werden nur dann benötigt, wenn Du die Zeitsteuerung über Dein Dashborad oder eine Deiner Automatisierungen modifizieren oder anzeigen möchtest.\r\rWenn Du Dir unsicher bist, füge die optionalen Zeitplanungs-Entitäten im ersten Schritt nicht hinzu. Sie können jederzeit über eine Einstellungen der Konfiguration zu einem späteren Zeitpunkt hinzugefügt werden.",
"data": {
"host": "IP oder Hostname deiner Waterkotte",
"username": "Benutzername",
"username": "Benutzername (bei den meisten Modellen ist dieser 'waterkotte')",
"password": "Passwort",
"polling_interval": "Aktualisierungsintervall in Sekunden",
"tags_per_request": "Anzahl von TAGS die gleichzeitig angefordert werden (max. 75)",
Expand All @@ -69,7 +69,7 @@
"data": {
"use_vent": "für eine 'Luftwärmepumpen-Außeneinheit'",
"use_heating_curve": "zur Anpassung von 'Heizkurven'",
"use_disinfection": "für die 'Warmwasser Disinfektion'",
"use_disinfection": "für die 'Warmwasser Desinfektion'",
"use_pool": "für eine 'Pooleinheit' (inkl. Heizkurve)"
}
}
Expand All @@ -87,7 +87,7 @@
"user": {
"description": "Wenn Du Hilfe bei der Einichtung benötigst, findest du sie hier: https://github.com/marq24/ha-waterkotte.\r\rWichtiger Hinweis: Mit dem 'Zeitprogramm anpassen Service' kannst Du alle Zeitpläne Deiner Waterkotte Heizung anpassen. Das Hinzufügen der optionalen Entitäten ist hierfür nicht notwendig. Diese werden nur dann benötigt, wenn Du die Zeitsteuerung über Dein Dashborad oder eine Deiner Automatisierungen modifizieren oder anzeigen möchtest.",
"data": {
"username": "Benutzername",
"username": "Benutzername (bei den meisten Modellen ist dieser 'waterkotte')",
"password": "Passwort",
"polling_interval": "Aktualisierungsintervall in Sekunden",
"tags_per_request": "Anzahl von TAGS die gleichzeitig angefordert werden (max. 75)",
Expand Down
1 change: 1 addition & 0 deletions custom_components/waterkotte_heatpump/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"description": "Important note: With the 'Adjust Schedules Service' you can adjust all schedules of your Waterkotte heat pump. Adding the optional entities is not necessary for this. These are only needed if you want to modify or display the schedule settings via your dashboard or one of your automations.\r\rIf you are unsure, do not add the optional scheduling entities in the first step. They can be added at any time via a configuration settings at a later date.",
"data": {
"host": "Host or IP",
"username": "Username",
"password": "Password",
"polling_interval": "Polling Interval in seconds",
"tags_per_request": "Number of tags to fetch in a single request (max. 75)",
Expand Down

0 comments on commit 95b024f

Please sign in to comment.