Skip to content

Commit

Permalink
Work through config_flow issues and warnings fixes #6 fixes #8 fixes #15
Browse files Browse the repository at this point in the history
  • Loading branch information
scheidtdav committed Dec 17, 2024
1 parent 55516d0 commit d0771db
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
25 changes: 22 additions & 3 deletions custom_components/kostal_piko/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Config flow for Kostal Piko solar inverters."""

import logging
from typing import Any

Expand Down Expand Up @@ -28,8 +29,12 @@ async def test_connection(
hass: HomeAssistant, data: dict[str, Any]
) -> tuple[str, str, str]:
"""Tests the connection to the inverter and returns its name."""
host = data["host"]
username = data["username"]
password = data["password"]

session = async_get_clientsession(hass)
inverter = kostal.Piko(session, data["host"], data["username"], data["password"])
inverter = kostal.Piko(session, host, username, password)
res = await inverter.fetch_props(
kostal.SettingsGeneral.INVERTER_NAME,
kostal.SettingsGeneral.INVERTER_MAKE,
Expand Down Expand Up @@ -60,12 +65,26 @@ async def async_step_user(

if user_input is not None:
try:
name, make, serial = await test_connection(self.hass, user_input)
host = user_input["host"]
username = user_input["username"]
password = user_input["password"]

# Opportunistically try to add http:// if neither http:// nor https:// is specified
if not host.startswith("http"):
host = "http://" + str(host)

# host cannot end with / since more path parameters are added to it by the library
if host.endswith("/"):
host = host[:-1]

setup_input = {"host": host, "username": username, "password": password}

name, make, serial = await test_connection(self.hass, setup_input)
await self.async_set_unique_id(serial)
self._abort_if_unique_id_configured()

return self.async_create_entry(
title=f"{make} {name} ({serial})", data=user_input
title=f"{make} {name} ({serial})", data=setup_input
)

except ValueError as err:
Expand Down
3 changes: 2 additions & 1 deletion custom_components/kostal_piko/const.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Constants for the Kostal Piko integration."""

from __future__ import annotations

from collections.abc import Callable
Expand Down Expand Up @@ -35,7 +36,7 @@
3: "feed_in",
4: "feed_in_limited",
7: "insulation_measurement",
8: "waiting_time"
8: "waiting_time",
}


Expand Down
2 changes: 1 addition & 1 deletion custom_components/kostal_piko/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"issue_tracker": "https://github.com/scheidtdav/homeassistant-kostal-piko/issues",
"iot_class": "local_polling",
"requirements": ["pykostal==0.0.2"],
"version": "24.01.0"
"version": "24.12.0"
}
7 changes: 6 additions & 1 deletion custom_components/kostal_piko/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
"step": {
"user": {
"data": {
"host": "Host",
"host": "Hostname oder IP Adresse",
"username": "Benutzername",
"password": "Passwort"
},
"data_description": {
"host": "Der Hostname oder die IP-Adresse (inkl. http:// oder https://) des Wechselrichters.",
"username": "Der Benutzername mit dem sich auf der Webseite des Wechselrichters eingeloggt wird.",
"password": "Das Passwort mit dem sich auf der Webseite des Wechselrichters eingeloggt wird."
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
"step": {
"user": {
"data": {
"host": "Host",
"host": "Host or IP",
"username": "Username",
"password": "Password"
},
"data_description": {
"host": "The hostname or IP address (including http:// or https://) of the inverter.",
"username": "The username used to log into the inverters webpage.",
"password": "The password used to log into the inverters webpage."
}
}
},
Expand Down

0 comments on commit d0771db

Please sign in to comment.