Skip to content

Commit

Permalink
✨ Adds support for Home Assistant integration discovery (#15)
Browse files Browse the repository at this point in the history
* ✨ Adds support for Home Assistant integration discovery

* 👕 Addresses linting warnings
  • Loading branch information
frenck committed Jun 11, 2019
1 parent e0a07f8 commit f6dbb7d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion adguard/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"url": "https://github.com/hassio-addons/addon-adguard-home",
"webui": "[PROTO:ssl]://[HOST]:[PORT:80]",
"ingress": true,
"ingress_port": 0,
"ingress_port": 45159,
"panel_icon": "mdi:shield-check",
"startup": "services",
"homeassistant": "0.92.0b2",
Expand All @@ -25,6 +25,9 @@
"53/udp": "DNS server port",
"80/tcp": "Web interface (Not required for Hass.io Ingress)"
},
"discovery": [
"adguard"
],
"boot": "auto",
"hassio_api": true,
"hassio_role": "default",
Expand Down
25 changes: 25 additions & 0 deletions adguard/rootfs/etc/cont-init.d/discovery.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Community Hass.io Add-ons: AdGuard Home
# Sends discovery information to Home Assistant.
# ==============================================================================
declare config
declare payload

config=$(\
bashio::var.json \
host "$(bashio::addon.ip_address)" \
port "^$(bashio::addon.ingress_port)" \
)

payload=$(\
bashio::var.json \
service adguard \
config "^${config}" \
)

if bashio::api.hassio "POST" "/discovery" "${payload}"; then
bashio::log.info "Successfully send discovery information to Home Assistant."
else
bashio::log.error "Discovery message to Home Assistant failed!"
fi
3 changes: 0 additions & 3 deletions adguard/rootfs/etc/cont-init.d/nginx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
declare admin_port
declare certfile
declare ingress_interface
declare ingress_port
declare keyfile

admin_port=$(bashio::addon.port 80)
Expand All @@ -28,7 +27,5 @@ if bashio::var.has_value "${admin_port}"; then
sed -i "s/%%port%%/${admin_port}/g" /etc/nginx/servers/direct.conf
fi

ingress_port=$(bashio::addon.ingress_port)
ingress_interface=$(bashio::addon.ip_address)
sed -i "s/%%port%%/${ingress_port}/g" /etc/nginx/servers/ingress.conf
sed -i "s/%%interface%%/${ingress_interface}/g" /etc/nginx/servers/ingress.conf
3 changes: 2 additions & 1 deletion adguard/rootfs/etc/nginx/servers/ingress.conf
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
server {
listen %%interface%%:%%port%% default_server;
listen %%interface%%:45159 default_server;

include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;

location / {
allow 172.30.32.1;
allow 172.30.32.2;
deny all;

Expand Down

0 comments on commit f6dbb7d

Please sign in to comment.