From e7bb759397a80452dea40220dd09ee52a47765cb Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 16 Feb 2020 10:57:04 +0100 Subject: [PATCH] :sparkles: Add hook up with the MQTT service --- vscode/config.json | 3 ++- vscode/rootfs/etc/cont-init.d/mosquitto.sh | 29 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 vscode/rootfs/etc/cont-init.d/mosquitto.sh diff --git a/vscode/config.json b/vscode/config.json index e1c563a..2d120df 100755 --- a/vscode/config.json +++ b/vscode/config.json @@ -10,11 +10,12 @@ "startup": "services", "arch": ["aarch64", "amd64"], "boot": "auto", + "auto_uart": true, "hassio_api": true, "hassio_role": "manager", "homeassistant_api": true, - "auto_uart": true, "map": ["config:rw", "ssl:rw", "addons:rw", "share:rw", "backup:rw"], + "services": ["mqtt:want"], "options": { "packages": [], "init_commands": [], diff --git a/vscode/rootfs/etc/cont-init.d/mosquitto.sh b/vscode/rootfs/etc/cont-init.d/mosquitto.sh new file mode 100644 index 0000000..79be1ee --- /dev/null +++ b/vscode/rootfs/etc/cont-init.d/mosquitto.sh @@ -0,0 +1,29 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Home Assistant Community Add-on: Visual Studio Code +# Pre-configures the Mosquitto clients, if the service is available +# ============================================================================== +declare host +declare password +declare port +declare username + +host=$(bashio::services "mqtt" "host") +if bashio::var.has_value "${host}"; then + password=$(bashio::services "mqtt" "password") + port=$(bashio::services "mqtt" "port") + username=$(bashio::services "mqtt" "username") + + mkdir -p /root/.config + { + echo "-h ${host}" + echo "--pw ${password}" + echo "--port ${port}" + echo "--username ${username}" + } > /root/.config/mosquitto_sub + + ln -s /root/.config/mosquitto_sub /root/.config/mosquitto_pub + ln -s /root/.config/mosquitto_sub /root/.config/mosquitto_rr +else + bashio::log.info "The above error can be ignored if you don't have Mosquitto installed" +fi