Skip to content

Commit

Permalink
deconz: Refactor (home-assistant#1476)
Browse files Browse the repository at this point in the history
* deconz: Refactor

* Disable shellcheck warning

* Fix wiringpi

* Bump version 6.0.0

* fix osram ota

* Revert file & update changelog

* Small bugfixes

* Exclude

Co-authored-by: Pascal Vizeli <[email protected]>
  • Loading branch information
frenck and pvizeli authored Jul 20, 2020
1 parent 014774a commit d0a50b9
Show file tree
Hide file tree
Showing 25 changed files with 302 additions and 224 deletions.
9 changes: 9 additions & 0 deletions deconz/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 6.0.0

- Use debian buster for all arch types
- Migrate to new S6-Overlay
- Fix LEDVANCE / OSRAM otau firmware downloader
- Bump deCONZ to 2.05.79
- New deCONZ firmware management on startup
- Exclude OTAU folder from snapshot

## 5.3.6

- Bump deCONZ to 2.05.78
Expand Down
13 changes: 4 additions & 9 deletions deconz/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/* \
&& if [ "${BUILD_ARCH}" = "armhf" ]; \
then \
curl -q -L -o /wiringpi.deb https://project-downloads.drogon.net/wiringpi-latest.deb \
&& dpkg -i /wiringpi.deb \
&& rm -rf /wiringpi.deb; \
curl -q -L -o /tmp/wiringpi.deb https://project-downloads.drogon.net/wiringpi-latest.deb \
&& dpkg --force-architecture -i /tmp/wiringpi.deb \
&& rm -rf /tmp/wiringpi.deb; \
fi

# Install deCONZ
Expand All @@ -55,9 +55,4 @@ RUN if [ "${BUILD_ARCH}" = "armhf" ]; \
&& chown root:root /usr/bin/deCONZ* \
&& sed -i 's/\/root/\/data/' /etc/passwd

COPY data/ika-otau-dl.sh /bin/
COPY data/ledvance-otau-dl.sh /bin/
COPY data/nginx.conf /etc/nginx/nginx.conf
COPY data/run.sh data/discovery.sh /

CMD ["/run.sh"]
COPY rootfs /
8 changes: 4 additions & 4 deletions deconz/build.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"build_from": {
"aarch64": "homeassistant/aarch64-base-debian:stretch",
"amd64": "homeassistant/amd64-base-ubuntu:18.04",
"armhf": "homeassistant/armhf-base-raspbian:stretch"
"aarch64": "homeassistant/aarch64-base-debian:buster",
"amd64": "homeassistant/amd64-base-debian:buster",
"armhf": "homeassistant/armhf-base-debian:buster"
},
"args": {
"DECONZ_VERSION": "2.05.78"
"DECONZ_VERSION": "2.05.79"
}
}
5 changes: 4 additions & 1 deletion deconz/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "deCONZ",
"version": "5.3.6",
"version": "6.0.0",
"slug": "deconz",
"description": "Control a Zigbee network with ConBee or RaspBee by Dresden Elektronik",
"arch": ["amd64", "armhf", "aarch64"],
Expand Down Expand Up @@ -29,6 +29,9 @@
"apparmor": false,
"privileged": ["SYS_MODULE", "SYS_RAWIO"],
"devices": ["/dev/bus/usb:/dev/bus/usb:rwm", "/dev/mem:/dev/mem:rw"],
"snapshot_exclude": [
"/data/otau/*"
],
"options": {
"device": null,
"vnc_password": ""
Expand Down
68 changes: 0 additions & 68 deletions deconz/data/discovery.sh

This file was deleted.

32 changes: 0 additions & 32 deletions deconz/data/ika-otau-dl.sh

This file was deleted.

42 changes: 0 additions & 42 deletions deconz/data/ledvance-otau-dl.sh

This file was deleted.

6 changes: 6 additions & 0 deletions deconz/rootfs/etc/cont-init.d/firmware.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Manage deCONZ firmware
# ==============================================================================

bashio::log.info "$(/usr/bin/GCFFlasher_internal -l)"
6 changes: 6 additions & 0 deletions deconz/rootfs/etc/cont-init.d/nginx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Configure NGINX for use with deCONZ
# ==============================================================================
ingress_entry=$(bashio::addon.ingress_entry)
sed -i "s#%%ingress_entry%%#${ingress_entry}#g" /etc/nginx/nginx.conf
19 changes: 19 additions & 0 deletions deconz/rootfs/etc/cont-init.d/vnc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Configure VNC for use with deCONZ
# ==============================================================================

# Check if VNC is enabled
VNC_PORT="$(bashio::addon.port 5900)"
if ! bashio::var.has_value "${VNC_PORT}"; then
# VNC is not enabled, skip this.
bashio::exit.ok
fi

# Require password when VNC is enabled
if ! bashio::config.has_value 'vnc_password'; then
bashio::exit.nok "VNC has been enabled, but no password has been set!"
fi

VNC_PASSWORD=$(bashio::config 'vnc_password')
echo "${VNC_PASSWORD}" | tigervncpasswd -f > /root/.vncpasswd
File renamed without changes.
70 changes: 70 additions & 0 deletions deconz/rootfs/etc/services.d/deconz/discovery
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Send deCONZ discovery information to Home Assistant
# ==============================================================================
readonly DATA_STORE="/data/.local/share/dresden-elektronik/deCONZ/zll.db"
declare api_key
declare config
declare query
declare retries
declare serial

# Wait for deCONZ to start before continuing
bashio::net.wait_for 40850

# Remove old discovery data storage (cleanup)
# We now query the deCONZ database for it directly.
if bashio::fs.file_exists /data/hassio.json; then
rm /data/hassio.json
fi

# Try to get API key from deCONZ database
query='SELECT apikey FROM auth WHERE devicetype="Home Assistant" ORDER BY createdate DESC LIMIT 1'
api_key=$(sqlite3 "${DATA_STORE}" "${query}" .exit)
if ! bashio::var.has_value "${api_key}"; then
# Register an API key for Home Assistant
if ! result="$(curl --silent --show-error --request POST -d '{"devicetype": "Home Assistant"}' "http://127.0.0.1:40850/api")";
then
bashio::log.debug "${result}"
bashio::exit.nok "Can't get API key from deCONZ gateway"
fi
api_key="$(bashio::jq "${result}" '.[0].success.username')"
fi

# Try to get the bridge ID/serial, try to avoid using 0000000000000000
retries=25
serial="0000000000000000"
while [[ "${serial}" = "0000000000000000" ]]; do
bashio::log.debug "Waiting for bridge ID..."
sleep 10

# If we tried 25 times, just abort.
if [[ "${retries}" -eq 0 ]]; then
bashio::exit.nok "Failed to get a valid bridge ID. Discovery aborted."
fi

# Get bridge ID from API
if ! result="$(curl --silent --show-error --request GET "http://127.0.0.1:40850/api/${api_key}/config")";
then
bashio::log.debug "${result}"
bashio::exit.nok "Can't get data from deCONZ gateway"
fi
serial="$(bashio::jq "${result}" '.bridgeid')"

((retries--))
done

# Create config payload for Home Assistant
config=$(bashio::var.json \
host "$(bashio::addon.ip_address)" \
port "^40850" \
api_key "${api_key}" \
serial "${serial}" \
)

# Send discovery info
if bashio::discovery "deconz" "${config}" > /dev/null; then
bashio::log.info "Successfully send discovery information to Home Assistant."
else
bashio::log.error "Discovery message to Home Assistant failed!"
fi
8 changes: 8 additions & 0 deletions deconz/rootfs/etc/services.d/deconz/finish
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/execlineb -S1
# ==============================================================================
# Take down the S6 supervision tree based on service exit code
# ==============================================================================
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }

s6-svscanctl -t /var/run/s6/services
Loading

0 comments on commit d0a50b9

Please sign in to comment.