M8-R01: add configurable MQTT client identity
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import replace
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -44,6 +45,7 @@ def fake_mqtt(monkeypatch):
|
||||
fake = _FakeMqtt()
|
||||
monkeypatch.setattr("app.integrations.mqtt.mqtt_manager", fake)
|
||||
monkeypatch.setattr(dsmr_ingest, "_subscriptions", {})
|
||||
monkeypatch.setattr(dsmr_ingest, "_subscription_client_ids", {})
|
||||
monkeypatch.setattr(dsmr_ingest, "_tariffs", {})
|
||||
return fake
|
||||
|
||||
@@ -81,6 +83,18 @@ def test_same_snapshot_has_no_subscription_churn(fake_mqtt, monkeypatch):
|
||||
assert fake_mqtt.remove_calls == []
|
||||
|
||||
|
||||
def test_changed_base_client_id_replaces_all_enabled_sources(fake_mqtt, monkeypatch):
|
||||
snapshot = _source(1, "topic", broker_host="broker.test")
|
||||
monkeypatch.setattr(dsmr_ingest, "_enabled_snapshots", lambda: [snapshot])
|
||||
|
||||
dsmr_ingest.apply_dsmr_subscription(SimpleNamespace(mqtt_client_id="home-automation"))
|
||||
dsmr_ingest.apply_dsmr_subscription(SimpleNamespace(mqtt_client_id="home-automation-dev"))
|
||||
|
||||
assert fake_mqtt.remove_calls == [1]
|
||||
assert [source_id for source_id, _ in fake_mqtt.replace_calls] == [1, 1]
|
||||
assert fake_mqtt.replace_calls[-1][1]["base_client_id"] == "home-automation-dev"
|
||||
|
||||
|
||||
def test_same_topic_on_different_brokers_is_allowed(fake_mqtt, monkeypatch):
|
||||
monkeypatch.setattr(
|
||||
dsmr_ingest,
|
||||
|
||||
Reference in New Issue
Block a user