From f04c4e9adba7c502acec5021719c232f202d5dbe Mon Sep 17 00:00:00 2001 From: Koen Hendriks Date: Tue, 2 Jan 2024 11:46:02 +0100 Subject: [PATCH] Fix mqtt broker endpoint when using internal supervisor network for mosquitto broker addon --- custom_components/button_plus/config_flow.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/custom_components/button_plus/config_flow.py b/custom_components/button_plus/config_flow.py index 51a9a09..e65d2a0 100644 --- a/custom_components/button_plus/config_flow.py +++ b/custom_components/button_plus/config_flow.py @@ -43,7 +43,7 @@ async def async_step_user(self, user_input=None): "mqtt_integration_link": mqtt_url }) mqtt_entry = mqtt_entries[0] - broker = mqtt_entry.data.get("broker") + broker = self.get_mqtt_endpoint(mqtt_entry.data.get("broker")) broker_port = mqtt_entry.data.get("port") broker_username = mqtt_entry.data.get("username", "(No authentication)") self.mqtt_entry = mqtt_entry @@ -198,7 +198,7 @@ def validate_ip(self, ip) -> bool: def add_broker_to_config(self, device_config: DeviceConfiguration) -> DeviceConfiguration: mqtt_entry = self.mqtt_entry - broker_endpoint = mqtt_entry.data.get("broker") + broker_endpoint = self.get_mqtt_endpoint(mqtt_entry.data.get("broker")) broker_port = mqtt_entry.data.get("port") broker_username = mqtt_entry.data.get("username", "") broker_password = mqtt_entry.data.get("password", "") @@ -227,3 +227,10 @@ def add_topics_to_buttons(self, device_config) -> DeviceConfiguration: }) return device_config + + def get_mqtt_endpoint(self, endpoint: str) -> str: + # Internal add-on is not reachable from the Button+ device so we use the hass ip + if endpoint == "core-mosquitto": + _LOGGER.debug(f'mqtt host is internal so use {self.hass.config.api.host}') + return self.hass.config.api.host + return endpoint