mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 01:38:02 +00:00

* Add APsystems local API integration * Fix session usage in config_flow in apsystems local api * Remove skip check option for apsystems_loca api * Update APsystems API dependency and increased test coverage to 100% * Utilize EntityDescriptions for APsystems Local integration * Ensure coverage entries are sorted (#114424) * Ensure coverage entries are sorted * Use autofix * Adjust * Add comment to coverage file * test CI * revert CI test --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Use patch instead of Http Mocks for APsystems API tests * Fix linter waring for apsystemsapi * Fix apsystemsapi test * Fix CODEOWNERS for apsystemsapi * Address small PR review changes for apsystems_local * Remove wrong lines in coveragerc * Add serial number for apsystems_local * Remove option of custom refresh interval fro apsystems_local * Remove function override and fix stale comments * Use native device id and name storage instead of custom one for apsystems_local * Use runtime_data for apsystems_local * Don't store entry data in runtime data * Move from apsystems_local to apsystems domain --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""The config_flow for APsystems local API integration."""
|
|
|
|
from aiohttp import client_exceptions
|
|
from APsystemsEZ1 import APsystemsEZ1M
|
|
import voluptuous as vol
|
|
|
|
from homeassistant import config_entries
|
|
from homeassistant.const import CONF_IP_ADDRESS
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from .const import DOMAIN, LOGGER
|
|
|
|
DATA_SCHEMA = vol.Schema(
|
|
{
|
|
vol.Required(CONF_IP_ADDRESS): str,
|
|
}
|
|
)
|
|
|
|
|
|
class APsystemsLocalAPIFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|
"""Config flow for Apsystems local."""
|
|
|
|
VERSION = 1
|
|
|
|
async def async_step_user(
|
|
self,
|
|
user_input: dict | None = None,
|
|
) -> config_entries.ConfigFlowResult:
|
|
"""Handle a flow initialized by the user."""
|
|
_errors = {}
|
|
session = async_get_clientsession(self.hass, False)
|
|
|
|
if user_input is not None:
|
|
try:
|
|
session = async_get_clientsession(self.hass, False)
|
|
api = APsystemsEZ1M(user_input[CONF_IP_ADDRESS], session=session)
|
|
device_info = await api.get_device_info()
|
|
await self.async_set_unique_id(device_info.deviceId)
|
|
except (TimeoutError, client_exceptions.ClientConnectionError) as exception:
|
|
LOGGER.warning(exception)
|
|
_errors["base"] = "connection_refused"
|
|
else:
|
|
return self.async_create_entry(
|
|
title="Solar",
|
|
data=user_input,
|
|
)
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=DATA_SCHEMA,
|
|
errors=_errors,
|
|
)
|