feat: update-Entitaet fuer die Firmware und das Testgeruest
Aufgebaut wie ha-ninlight: die Abbilder liegen unter ninstrip_firmware im Konfigurationsverzeichnis, Home Assistant liefert sie selbst unter einer einmaligen Adresse aus, und zwar genau die Bytes, die vorher geprueft wurden. Dazu firmware.py (Anhaenger, Versionsreihenfolge, WLAN-Pruefung, Katalog), http.py, urls.py und shared.py. Drei Unterschiede zu ninlight, alle aus der Firmware heraus: * Verglichen wird device_type - die Platine -, nicht product. Letzteres ist bei allen Platinen 'ninstrip'; die Abbilder unterscheiden sich aber hart, die K1Y invertiert das Datensignal und die KL-RGBC3 nicht. Firmware ohne dieses Feld bekommt gar kein Angebot. * Die WLAN-Pruefung sucht die SSID unverpackt: ein ESP32-Abbild ist nicht gzip-verpackt wie das des W600. An einem mit sdkconfig.local gebauten Abbild gegengeprueft - die SSID steht genau einmal NUL-gerahmt drin. * Der Fehlerschluessel heisst device_url_too_long statt lamp_url_too_long. Dazu das Testgeruest, das es hier bisher gar nicht gab: 204 Tests in tests_unit/ (ohne HA-Instanz) und tests/ (mit), Abdeckung 97 %, dazu scripts/check.sh als Ersatz fuer die fehlende CI. Die Nutzdaten in tests_unit/samples.py sind an der Stehlampe abgefragt. Beim Gegenpruefen per Mutation fiel auf, dass die Platinenpruefung unmittelbar vor dem Senden ungeprueft war - der Test dazu ist jetzt da und faellt, wenn man die Pruefung entfernt.
This commit is contained in:
@@ -21,6 +21,7 @@ import voluptuous as vol
|
||||
|
||||
from .api import NinstripAuthError, NinstripClient, NinstripError, NinstripResponseError
|
||||
from .const import (
|
||||
CONF_DEVICE_BASE_URL,
|
||||
CONF_SCAN_INTERVAL,
|
||||
DEFAULT_SCAN_INTERVAL,
|
||||
DEFAULT_TOKEN,
|
||||
@@ -29,6 +30,7 @@ from .const import (
|
||||
MIN_SCAN_INTERVAL,
|
||||
)
|
||||
from .entity import device_name
|
||||
from .urls import validate_device_base_url
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -78,18 +80,12 @@ class NinstripConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
title=device_name(info), data={CONF_HOST: host, CONF_TOKEN: token}
|
||||
)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
async def async_step_user(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
|
||||
errors: dict[str, str] = {}
|
||||
if user_input is not None:
|
||||
info, errors = await self._async_probe(
|
||||
user_input[CONF_HOST], user_input[CONF_TOKEN]
|
||||
)
|
||||
info, errors = await self._async_probe(user_input[CONF_HOST], user_input[CONF_TOKEN])
|
||||
if info is not None:
|
||||
return await self._async_finish(
|
||||
user_input[CONF_HOST], user_input[CONF_TOKEN], info
|
||||
)
|
||||
return await self._async_finish(user_input[CONF_HOST], user_input[CONF_TOKEN], info)
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
data_schema=vol.Schema(
|
||||
@@ -101,9 +97,7 @@ class NinstripConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_zeroconf(
|
||||
self, discovery_info: ZeroconfServiceInfo
|
||||
) -> ConfigFlowResult:
|
||||
async def async_step_zeroconf(self, discovery_info: ZeroconfServiceInfo) -> ConfigFlowResult:
|
||||
"""Gefunden ueber _ninstrip._tcp."""
|
||||
self._host = discovery_info.host
|
||||
props = discovery_info.properties or {}
|
||||
@@ -131,9 +125,7 @@ class NinstripConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_reauth(
|
||||
self, entry_data: Mapping[str, Any]
|
||||
) -> ConfigFlowResult:
|
||||
async def async_step_reauth(self, entry_data: Mapping[str, Any]) -> ConfigFlowResult:
|
||||
self._host = entry_data[CONF_HOST]
|
||||
return await self.async_step_reauth_confirm()
|
||||
|
||||
@@ -158,21 +150,36 @@ class NinstripConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
|
||||
class NinstripOptionsFlow(OptionsFlowWithReload):
|
||||
"""Bisher nur die Abfragehaeufigkeit."""
|
||||
"""Abfragehaeufigkeit und die Adresse, unter der Geraete Home Assistant erreichen."""
|
||||
|
||||
async def async_step_init(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
async def async_step_init(self, user_input: dict[str, Any] | None = None) -> ConfigFlowResult:
|
||||
errors: dict[str, str] = {}
|
||||
if user_input is not None:
|
||||
return self.async_create_entry(data=user_input)
|
||||
current = self.config_entry.options.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
||||
base = str(user_input.get(CONF_DEVICE_BASE_URL) or "").strip()
|
||||
fehler = validate_device_base_url(base) if base else None
|
||||
if fehler:
|
||||
errors[CONF_DEVICE_BASE_URL] = fehler
|
||||
else:
|
||||
daten: dict[str, Any] = {CONF_SCAN_INTERVAL: user_input[CONF_SCAN_INTERVAL]}
|
||||
if base:
|
||||
daten[CONF_DEVICE_BASE_URL] = base.rstrip("/")
|
||||
return self.async_create_entry(data=daten)
|
||||
current = self.config_entry.options
|
||||
return self.async_show_form(
|
||||
step_id="init",
|
||||
data_schema=vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_SCAN_INTERVAL, default=current): vol.All(
|
||||
vol.Required(
|
||||
CONF_SCAN_INTERVAL,
|
||||
default=current.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL),
|
||||
): vol.All(
|
||||
vol.Coerce(int), vol.Range(min=MIN_SCAN_INTERVAL, max=MAX_SCAN_INTERVAL)
|
||||
)
|
||||
),
|
||||
vol.Optional(
|
||||
CONF_DEVICE_BASE_URL,
|
||||
description={"suggested_value": current.get(CONF_DEVICE_BASE_URL, "")},
|
||||
): str,
|
||||
}
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user