Skip to content

Commit 67b9904

Browse files
Add Kostal plenticore Installer login support (#133773)
* feat: Add Installer login, Add ManualCharge Switch * remove unnecessary field * replace strings with consts * change to CONF and camel_case * Improve existing code * Add translation string * format code * add service code test * format code * format code * remove manual charge switch * add reconfigure config flow * fix flow * add return type * add reconfigure strings * adjust tests * change string * simlify tests * add reconfigure test * add more tests * Fix --------- Co-authored-by: Joost Lekkerkerker <[email protected]>
1 parent e413e9b commit 67b9904

File tree

5 files changed

+335
-29
lines changed

5 files changed

+335
-29
lines changed

homeassistant/components/kostal_plenticore/config_flow.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from homeassistant.core import HomeAssistant
1313
from homeassistant.helpers.aiohttp_client import async_get_clientsession
1414

15-
from .const import DOMAIN
15+
from .const import CONF_SERVICE_CODE, DOMAIN
1616
from .helper import get_hostname_id
1717

1818
_LOGGER = logging.getLogger(__name__)
@@ -21,6 +21,7 @@
2121
{
2222
vol.Required(CONF_HOST): str,
2323
vol.Required(CONF_PASSWORD): str,
24+
vol.Optional(CONF_SERVICE_CODE): str,
2425
}
2526
)
2627

@@ -32,8 +33,10 @@ async def test_connection(hass: HomeAssistant, data) -> str:
3233
"""
3334

3435
session = async_get_clientsession(hass)
35-
async with ApiClient(session, data["host"]) as client:
36-
await client.login(data["password"])
36+
async with ApiClient(session, data[CONF_HOST]) as client:
37+
await client.login(
38+
data[CONF_PASSWORD], service_code=data.get(CONF_SERVICE_CODE)
39+
)
3740
hostname_id = await get_hostname_id(client)
3841
values = await client.get_setting_values("scb:network", hostname_id)
3942

@@ -70,3 +73,30 @@ async def async_step_user(
7073
return self.async_show_form(
7174
step_id="user", data_schema=DATA_SCHEMA, errors=errors
7275
)
76+
77+
async def async_step_reconfigure(
78+
self, user_input: dict[str, Any] | None = None
79+
) -> ConfigFlowResult:
80+
"""Add reconfigure step to allow to reconfigure a config entry."""
81+
errors = {}
82+
83+
if user_input is not None:
84+
self._async_abort_entries_match({CONF_HOST: user_input[CONF_HOST]})
85+
try:
86+
hostname = await test_connection(self.hass, user_input)
87+
except AuthenticationException as ex:
88+
errors[CONF_PASSWORD] = "invalid_auth"
89+
_LOGGER.error("Error response: %s", ex)
90+
except (ClientError, TimeoutError):
91+
errors[CONF_HOST] = "cannot_connect"
92+
except Exception:
93+
_LOGGER.exception("Unexpected exception")
94+
errors[CONF_BASE] = "unknown"
95+
else:
96+
return self.async_update_reload_and_abort(
97+
entry=self._get_reconfigure_entry(), title=hostname, data=user_input
98+
)
99+
100+
return self.async_show_form(
101+
step_id="reconfigure", data_schema=DATA_SCHEMA, errors=errors
102+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
"""Constants for the Kostal Plenticore Solar Inverter integration."""
22

33
DOMAIN = "kostal_plenticore"
4+
CONF_SERVICE_CODE = "service_code"

homeassistant/components/kostal_plenticore/coordinator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from homeassistant.helpers.event import async_call_later
2626
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
2727

28-
from .const import DOMAIN
28+
from .const import CONF_SERVICE_CODE, DOMAIN
2929
from .helper import get_hostname_id
3030

3131
_LOGGER = logging.getLogger(__name__)
@@ -60,7 +60,10 @@ async def async_setup(self) -> bool:
6060
async_get_clientsession(self.hass), host=self.host
6161
)
6262
try:
63-
await self._client.login(self.config_entry.data[CONF_PASSWORD])
63+
await self._client.login(
64+
self.config_entry.data[CONF_PASSWORD],
65+
service_code=self.config_entry.data.get(CONF_SERVICE_CODE),
66+
)
6467
except AuthenticationException as err:
6568
_LOGGER.error(
6669
"Authentication exception connecting to %s: %s", self.host, err

homeassistant/components/kostal_plenticore/strings.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
"user": {
55
"data": {
66
"host": "[%key:common::config_flow::data::host%]",
7-
"password": "[%key:common::config_flow::data::password%]"
7+
"password": "[%key:common::config_flow::data::password%]",
8+
"service_code": "Service code"
9+
}
10+
},
11+
"reconfigure": {
12+
"data": {
13+
"host": "[%key:common::config_flow::data::host%]",
14+
"password": "[%key:common::config_flow::data::password%]",
15+
"service_code": "[%key:component::kostal_plenticore::config::step::user::data::service_code%]"
816
}
917
}
1018
},
@@ -14,7 +22,8 @@
1422
"unknown": "[%key:common::config_flow::error::unknown%]"
1523
},
1624
"abort": {
17-
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
25+
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
26+
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
1827
}
1928
}
2029
}

0 commit comments

Comments
 (0)