Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 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
35 changes: 32 additions & 3 deletions homeassistant/components/kostal_plenticore/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import DOMAIN
from .const import CONF_SERVICE_CODE, DOMAIN
from .helper import get_hostname_id

_LOGGER = logging.getLogger(__name__)
Expand All @@ -21,6 +21,7 @@
{
vol.Required(CONF_HOST): str,
vol.Required(CONF_PASSWORD): str,
vol.Optional(CONF_SERVICE_CODE): str,
}
)

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

session = async_get_clientsession(hass)
async with ApiClient(session, data["host"]) as client:
await client.login(data["password"])
async with ApiClient(session, data[CONF_HOST]) as client:
await client.login(
data[CONF_PASSWORD], service_code=data.get(CONF_SERVICE_CODE)
)
hostname_id = await get_hostname_id(client)
values = await client.get_setting_values("scb:network", hostname_id)

Expand Down Expand Up @@ -70,3 +73,29 @@ async def async_step_user(
return self.async_show_form(
step_id="user", data_schema=DATA_SCHEMA, errors=errors
)

async def async_step_reconfigure(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Add reconfigure step to allow to reconfigure a config entry."""
errors = {}

if user_input is not None:
try:
hostname = await test_connection(self.hass, user_input)
except AuthenticationException as ex:
errors[CONF_PASSWORD] = "invalid_auth"
_LOGGER.error("Error response: %s", ex)
except (ClientError, TimeoutError):
errors[CONF_HOST] = "cannot_connect"
except Exception:
_LOGGER.exception("Unexpected exception")
errors[CONF_BASE] = "unknown"
else:
return self.async_update_reload_and_abort(
entry=self._get_reconfigure_entry(), title=hostname, data=user_input
)

return self.async_show_form(
step_id="reconfigure", data_schema=DATA_SCHEMA, errors=errors
)
1 change: 1 addition & 0 deletions homeassistant/components/kostal_plenticore/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Constants for the Kostal Plenticore Solar Inverter integration."""

DOMAIN = "kostal_plenticore"
CONF_SERVICE_CODE = "service_code"
7 changes: 5 additions & 2 deletions homeassistant/components/kostal_plenticore/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator

from .const import DOMAIN
from .const import CONF_SERVICE_CODE, DOMAIN
from .helper import get_hostname_id

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -60,7 +60,10 @@ async def async_setup(self) -> bool:
async_get_clientsession(self.hass), host=self.host
)
try:
await self._client.login(self.config_entry.data[CONF_PASSWORD])
await self._client.login(
self.config_entry.data[CONF_PASSWORD],
service_code=self.config_entry.data.get(CONF_SERVICE_CODE),
)
except AuthenticationException as err:
_LOGGER.error(
"Authentication exception connecting to %s: %s", self.host, err
Expand Down
13 changes: 11 additions & 2 deletions homeassistant/components/kostal_plenticore/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
"user": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"password": "[%key:common::config_flow::data::password%]"
"password": "[%key:common::config_flow::data::password%]",
"service_code": "Service code"
}
},
"reconfigure": {
"data": {
"host": "[%key:common::config_flow::data::host%]",
"password": "[%key:common::config_flow::data::password%]",
"service_code": "[%key:component::kostal_plenticore::config::step::user::data::service_code%]"
}
}
},
Expand All @@ -14,7 +22,8 @@
"unknown": "[%key:common::config_flow::error::unknown%]"
},
"abort": {
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]",
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
}
}
}
Loading
Loading