* Implement TechnoVE integration Only the basic sensors for now. * Add technoVE to strict typing * Implement TechnoVE PR suggestions * Remove Diagnostic from TechnoVE initial PR * Switch status sensor to Enum device class * Revert zeroconf for adding it back in subsequent PR * Implement changes from feedback in TechnoVE PR * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/technove/sensor.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Remove unnecessary translation keys * Fix existing technoVE tests * Use snapshot testing for TechnoVE sensors * Improve unit tests for TechnoVE * Add missing coverage for technoVE config flow * Add TechnoVE coordinator tests * Modify device_fixture for TechnoVE from PR Feedback * Change CONF_IP_ADDRESS to CONF_HOST for TechnoVE * Update homeassistant/components/technove/config_flow.py Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com> * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Update homeassistant/components/technove/models.py Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> * Implement feedback from TechnoVE PR * Add test_sensor_update_failure to TechnoVE sensor tests * Add test for error recovery during config flow of TechnoVE * Remove test_coordinator.py from TechnoVE --------- Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com> Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
50 lines
1.7 KiB
Python
50 lines
1.7 KiB
Python
"""Config flow for TechnoVE."""
|
|
|
|
from typing import Any
|
|
|
|
from technove import Station as TechnoVEStation, TechnoVE, TechnoVEConnectionError
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.config_entries import ConfigFlow
|
|
from homeassistant.const import CONF_HOST
|
|
from homeassistant.data_entry_flow import FlowResult
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from .const import DOMAIN
|
|
|
|
|
|
class TechnoVEConfigFlow(ConfigFlow, domain=DOMAIN):
|
|
"""Handle a config flow for TechnoVE."""
|
|
|
|
async def async_step_user(
|
|
self, user_input: dict[str, Any] | None = None
|
|
) -> FlowResult:
|
|
"""Handle a flow initiated by the user."""
|
|
errors = {}
|
|
if user_input is not None:
|
|
try:
|
|
station = await self._async_get_station(user_input[CONF_HOST])
|
|
except TechnoVEConnectionError:
|
|
errors["base"] = "cannot_connect"
|
|
else:
|
|
await self.async_set_unique_id(station.info.mac_address)
|
|
self._abort_if_unique_id_configured(
|
|
updates={CONF_HOST: user_input[CONF_HOST]}
|
|
)
|
|
return self.async_create_entry(
|
|
title=station.info.name,
|
|
data={
|
|
CONF_HOST: user_input[CONF_HOST],
|
|
},
|
|
)
|
|
|
|
return self.async_show_form(
|
|
step_id="user",
|
|
data_schema=vol.Schema({vol.Required(CONF_HOST): str}),
|
|
errors=errors,
|
|
)
|
|
|
|
async def _async_get_station(self, host: str) -> TechnoVEStation:
|
|
"""Get information from a TechnoVE station."""
|
|
api = TechnoVE(host, session=async_get_clientsession(self.hass))
|
|
return await api.update()
|