From 6847f767cdfff5801007f182e7f00714a9c04339 Mon Sep 17 00:00:00 2001 From: olijouve <17448560+olijouve@users.noreply.github.com> Date: Sat, 11 Jan 2020 13:26:36 +0100 Subject: [PATCH] deconz: Add LEDVANCE / OSRAM otau firmware downloader (#983) * Update config.json * Create ledvance-otau-dl.sh * Update run.sh * Update Dockerfile * Update CHANGELOG.md * Update CHANGELOG.md * Update ledvance-otau-dl.sh Fix lint issues: https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt... https://www.shellcheck.net/wiki/SC2003 -- expr is antiquated. Consider rewr... * Update ledvance-otau-dl.sh Fix lint issue: https://www.shellcheck.net/wiki/SC2004 -- $/${} is unnecessary on arithmeti... * Update Dockerfile Adressing @pvizeli comment : The script have the correct permission of a+x? Add CMD to set a+x permission on ledvance-otau-dl.sh script * Update Dockerfile * Add exec permissions * revert oups bad multiple cmdlines in CMD[] * revert oups bad multiple cmdlines in CMD[] * dummy commit * Update Dockerfile remove dummy comment * Update ledvance-otau-dl.sh remove dummy comment * fix bug Co-authored-by: Pascal Vizeli --- deconz/CHANGELOG.md | 4 ++++ deconz/Dockerfile | 1 + deconz/config.json | 2 +- deconz/data/ledvance-otau-dl.sh | 42 +++++++++++++++++++++++++++++++++ deconz/data/run.sh | 4 ++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 deconz/data/ledvance-otau-dl.sh diff --git a/deconz/CHANGELOG.md b/deconz/CHANGELOG.md index beb97dd..7bf9c5a 100644 --- a/deconz/CHANGELOG.md +++ b/deconz/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 5.1 + +- Add LEDVANCE / OSRAM otau firmware downloader, respecting max 10 DL per minute Ratelimits + ## 5.0 - Fix additional gateway visible on Phoscon login on Ingress diff --git a/deconz/Dockerfile b/deconz/Dockerfile index 0c15e57..3c342ee 100644 --- a/deconz/Dockerfile +++ b/deconz/Dockerfile @@ -56,6 +56,7 @@ RUN if [ "${BUILD_ARCH}" = "armhf" ]; \ && 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 / diff --git a/deconz/config.json b/deconz/config.json index d157d6c..5b5edaf 100644 --- a/deconz/config.json +++ b/deconz/config.json @@ -1,6 +1,6 @@ { "name": "deCONZ", - "version": "5.0", + "version": "5.1", "slug": "deconz", "description": "Control a Zigbee network with ConBee or RaspBee by Dresden Elektronik", "arch": ["amd64", "armhf", "aarch64"], diff --git a/deconz/data/ledvance-otau-dl.sh b/deconz/data/ledvance-otau-dl.sh new file mode 100755 index 0000000..7890685 --- /dev/null +++ b/deconz/data/ledvance-otau-dl.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +URL_OSRAM="https://api.update.ledvance.com/v1/zigbee/firmwares" + +while true +do + + # fetch data + if ! OSRAM_DATA="$(curl -sL ${URL_OSRAM})"; then + echo "[Info] Can't fetch data from osram!" + sleep 18000 + continue + fi + + OSRAM_DATA_SIZE="$(echo "${OSRAM_DATA}" | jq --raw-output '.firmwares | length')" + DL_DONE=0 + for (( i=0; i < "${OSRAM_DATA_SIZE}"; i++ )); do + OSRAM_COMPANY=$( echo "${OSRAM_DATA}" | jq --raw-output ".firmwares[$i].identity.company // empty" 2>/dev/null) + OSRAM_PRODUCT=$( echo "${OSRAM_DATA}" | jq --raw-output ".firmwares[$i].identity.product // empty" 2>/dev/null) + OTAU_FILENAME=$( echo "${OSRAM_DATA}" | jq --raw-output ".firmwares[$i].name // empty" 2>/dev/null) + OTAU_URL="$URL_OSRAM/download/${OSRAM_COMPANY}/${OSRAM_PRODUCT}/latest" + + if [ -z "${OTAU_URL}" ]; then + continue + fi + + + OTAU_FILE="/data/otau/${OTAU_FILENAME}" + if [ -f "${OTAU_FILE}" ] && [[ $(file --mime-type -b "${OTAU_FILE}") == "application/octet-stream" ]] ; then + continue + fi + curl -s -L -o "${OTAU_FILE}" "${OTAU_URL}" + ((DL_DONE++)) + if [ "$((DL_DONE % 10))" == "0" ]; then + # LEDVANCE/OSRAM API RateLimits : The rate limit 10 calls per 60 seconds or quota 100 MB per month. + DL_DONE=0 + sleep 65 + fi + done + + sleep 259200 +done diff --git a/deconz/data/run.sh b/deconz/data/run.sh index 5f63422..ef4b291 100755 --- a/deconz/data/run.sh +++ b/deconz/data/run.sh @@ -123,6 +123,10 @@ deCONZ-otau-dl.sh &> /dev/null & bashio::log.info "Running the IKEA OTA updater..." ika-otau-dl.sh &> /dev/null & +# Start OTA updates for LEDVANCE/OSRAM +bashio::log.info "Running the LEDVANCE/OSRAM OTA updater..." +ledvance-otau-dl.sh &> /dev/null & + # Wait until all is done bashio::log.info "deCONZ is set up and running!" wait "${WAIT_PIDS[@]}"