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:
@@ -4,11 +4,17 @@ from __future__ import annotations
|
||||
|
||||
from homeassistant.const import CONF_HOST, CONF_TOKEN, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .api import NinstripClient
|
||||
from .const import DEFAULT_PORT
|
||||
from .const import DEFAULT_PORT, DOMAIN
|
||||
from .coordinator import NinstripConfigEntry, NinstripCoordinator
|
||||
from .shared import async_get_shared, async_start_catalog, async_stop_catalog
|
||||
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.LIGHT,
|
||||
@@ -18,9 +24,16 @@ PLATFORMS: list[Platform] = [
|
||||
Platform.SWITCH,
|
||||
Platform.NUMBER,
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.UPDATE,
|
||||
]
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Die Ausgabe fuer die Abbilder haengt an http und wird einmal angemeldet."""
|
||||
async_get_shared(hass)
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> bool:
|
||||
"""Einen Strip einrichten."""
|
||||
client = NinstripClient(
|
||||
@@ -33,13 +46,27 @@ async def async_setup_entry(hass: HomeAssistant, entry: NinstripConfigEntry) ->
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
|
||||
entry.runtime_data = coordinator
|
||||
await async_start_catalog(hass, async_get_shared(hass))
|
||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||
entry.async_on_unload(entry.add_update_listener(_async_options_updated))
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> bool:
|
||||
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
entladen = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||
# Der Katalog gehoert allen Eintraegen gemeinsam; er laeuft weiter,
|
||||
# solange noch einer da ist.
|
||||
if entladen and not [
|
||||
anderer
|
||||
for anderer in hass.config_entries.async_loaded_entries(DOMAIN)
|
||||
if anderer.entry_id != entry.entry_id
|
||||
]:
|
||||
async_stop_catalog(async_get_shared(hass))
|
||||
return entladen
|
||||
|
||||
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: NinstripConfigEntry) -> None:
|
||||
ir.async_delete_issue(hass, DOMAIN, f"wifi_guard_{entry.entry_id}")
|
||||
|
||||
|
||||
async def _async_options_updated(hass: HomeAssistant, entry: NinstripConfigEntry) -> None:
|
||||
|
||||
Reference in New Issue
Block a user