ha_discovery: publish state/availability under home_automation prefix
Follow the standard MQTT Discovery split: discovery config stays under the HA discovery prefix (homeassistant/.../config, required), but the actual state and availability are published under our own prefix (default home_automation/). The config payload's state_topic/availability fields point at the new prefix so HA reads state from there. - new config ha_state_topic_prefix (default home_automation). - build_discovery_payload + all publish_* split discovery_prefix (config topic) from state_prefix (state/availability). energy-cost still omits availability; modbus availability structure unchanged. Tests updated.
This commit is contained in:
@@ -90,11 +90,13 @@ def _make_settings(
|
||||
mqtt_enabled: bool = True,
|
||||
ha_discovery_enabled: bool = True,
|
||||
ha_discovery_prefix: str = "homeassistant",
|
||||
ha_state_topic_prefix: str = "home_automation",
|
||||
) -> MagicMock:
|
||||
s = MagicMock()
|
||||
s.mqtt_enabled = mqtt_enabled
|
||||
s.ha_discovery_enabled = ha_discovery_enabled
|
||||
s.ha_discovery_prefix = ha_discovery_prefix
|
||||
s.ha_state_topic_prefix = ha_state_topic_prefix
|
||||
return s
|
||||
|
||||
|
||||
@@ -691,7 +693,7 @@ def test_energy_entity_discovery_topics_contain_correct_node_id() -> None:
|
||||
state_class="total",
|
||||
)
|
||||
|
||||
topic, config = build_discovery_payload(entity, prefix="homeassistant")
|
||||
topic, config = build_discovery_payload(entity, discovery_prefix="homeassistant")
|
||||
|
||||
# node_id: hyphens replaced with underscores → "energy_cost"
|
||||
expected_node = "energy_cost"
|
||||
|
||||
Reference in New Issue
Block a user