Skip to content

Commit

Permalink
Fix mqtt broker endpoint when using internal supervisor network for m…
Browse files Browse the repository at this point in the history
…osquitto broker addon
  • Loading branch information
koenhendriks committed Jan 2, 2024
1 parent 53e455c commit f04c4e9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions custom_components/button_plus/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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", "")
Expand Down Expand Up @@ -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

0 comments on commit f04c4e9

Please sign in to comment.