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:
co-authored by
Claude Sonnet 4.6
parent
83035fed0e
commit
10e21f031a
@@ -21,11 +21,13 @@ class MqttPublisher:
|
||||
self._registered: List[Tuple] = []
|
||||
self._agg_meta: Dict = agg_meta or {}
|
||||
|
||||
self._subscriptions: List[Tuple[str, any]] = []
|
||||
self._client = mqtt.Client(client_id="shinebridge_hub", clean_session=True)
|
||||
if user:
|
||||
self._client.username_pw_set(user, password)
|
||||
self._client.on_connect = self._on_connect
|
||||
self._client.on_disconnect = self._on_disconnect
|
||||
self._client.on_message = self._on_message
|
||||
|
||||
def _on_connect(self, client, userdata, flags, rc):
|
||||
if rc == 0:
|
||||
@@ -35,6 +37,8 @@ class MqttPublisher:
|
||||
self._publish_discovery(*entry)
|
||||
if self._agg_meta:
|
||||
self._publish_aggregate_discovery()
|
||||
for topic, _ in self._subscriptions:
|
||||
client.subscribe(topic)
|
||||
else:
|
||||
log.error("MQTT Verbindungsfehler rc=%d", rc)
|
||||
|
||||
@@ -42,6 +46,19 @@ class MqttPublisher:
|
||||
self._connected = False
|
||||
log.warning("MQTT getrennt rc=%d", rc)
|
||||
|
||||
def _on_message(self, client, userdata, msg):
|
||||
for topic, callback in self._subscriptions:
|
||||
if mqtt.topic_matches_sub(topic, msg.topic):
|
||||
try:
|
||||
callback(msg.topic, msg.payload)
|
||||
except Exception as e:
|
||||
log.error("MQTT message handler Fehler [%s]: %s", msg.topic, e)
|
||||
|
||||
def subscribe(self, topic: str, callback):
|
||||
self._subscriptions.append((topic, callback))
|
||||
if self._connected:
|
||||
self._client.subscribe(topic)
|
||||
|
||||
def connect(self):
|
||||
try:
|
||||
self._client.connect_async(self._broker, self._port, keepalive=60)
|
||||
|
||||
Reference in New Issue
Block a user