v1.8.9: Z2M Geräte-Dropdown für Überschuss-Steuerung

- MQTT Subscribe auf zigbee2mqtt/bridge/devices beim Connect
- Neuer Endpoint GET /api/z2m-devices liefert Friendly Names + Beschreibung
- Eingabefeld für Z2M Name als Datalist-Combo (tippen oder aus Liste wählen)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
retr0
2026-05-04 10:57:52 +02:00
parent 83035fed0e
commit 10e21f031a
3 changed files with 59 additions and 2 deletions
+28
View File
@@ -76,6 +76,7 @@ class State:
inv_data: Dict[str, Dict[str, Any]] = {}
surplus_devices_cfg: List[Dict[str, Any]] = []
z2m_base: str = "zigbee2mqtt"
z2m_devices: List[Dict[str, Any]] = []
_publisher: Optional[MqttPublisher] = None
_surplus_ctrl: Optional[SurplusDeviceController] = None
@@ -370,6 +371,28 @@ def _restart_all():
_surplus_ctrl.set_config(devices, z2m_base)
_start_surplus_loop()
def _on_z2m_devices(topic, payload):
try:
devices_raw = json.loads(payload)
if not isinstance(devices_raw, list):
return
parsed = [
{
"friendly_name": d.get("friendly_name", ""),
"description": (d.get("definition") or {}).get("description", ""),
"type": d.get("type", ""),
}
for d in devices_raw
if d.get("friendly_name") and d.get("friendly_name") != "Coordinator"
]
with State.lock:
State.z2m_devices = parsed
log.info("Z2M: %d Geräte empfangen", len(parsed))
except Exception as e:
log.warning("Z2M bridge/devices Fehler: %s", e)
_publisher.subscribe(f"{z2m_base}/bridge/devices", _on_z2m_devices)
for inv_cfg in State.inverters_cfg:
_start_inverter(inv_cfg)
@@ -488,6 +511,11 @@ def api_period_energy():
return jsonify(result)
@app.get("/api/z2m-devices")
def api_z2m_devices():
with State.lock:
return jsonify(State.z2m_devices)
@app.get("/api/surplus-devices")
def api_get_surplus_devices():
with State.lock: