From 27cdea6924564b54d67e1a62c7aa4aeb31c0b7f4 Mon Sep 17 00:00:00 2001 From: Sebastian Schubotz Date: Thu, 22 Feb 2024 16:20:47 +0100 Subject: [PATCH] Allow additional env vars for Hass Add-On + add missing config params (#111) * Add ADDITIONAL_ENV_VARS hassio option * Bump to v1.0.7 * Add missing config options to run.sh * Add changelog * Update readme * Make non-required options optional --- CHANGELOG.md | 12 ++++++++++++ README.md | 13 +++++++++++++ config.yaml | 32 ++++++++++++++++++++------------ package.json | 2 +- run.sh | 20 ++++++++++++++++++-- 5 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b2c2b82 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +## 1.0.7 + +### Added + +* Finally there's a changelog +* Allow custom environment variables to Home Assistant Add-On + +### Fixed + +* Add missing config variables to Home Assistant Add-On diff --git a/README.md b/README.md index 1fdb0f0..6f53342 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,19 @@ Home Assistant related stuff: If you use `HA_SCREENSHOT_URL_2`, you can also set `ROTATION_2=180`. If there is no `ROTATION_n` set, then `ROTATION` will be used as a fallback. You can access these additional images by making GET Requests `http://localhost:5000/2`, `http://localhost:5000/3` etc. +To make us of the array feature in the Home Assistant Add-On, you may use `ADDITIONAL_ENV_VARS`. It expects a format like this to set any additional environment variable: + +```yaml +- name: "HA_SCREENSHOT_URL_2" + value: "/lovelace/second-page" +- name: "ROTATION_2" + value: "180" +- name: "HA_SCREENSHOT_URL_3" + value: "/lovelace/third-page" +``` + +To avoid problems, please ensure that the name only contains upper case letters, numbers and underscores. The value field must be a string, so it's better to always put your value (especially numbers) into a `"string"` . + ### How to set up the webhook The webhook setting is to let HA keep track of the battery level of the Kindle, so it can warn you about charging it. You need to do the following: diff --git a/config.yaml b/config.yaml index ff309ea..f21e689 100644 --- a/config.yaml +++ b/config.yaml @@ -1,5 +1,5 @@ name: Lovelace Kindle Screensaver -version: 1.0.6 +version: 1.0.7 slug: kindle-screensaver description: This tool can be used to display a Lovelace view of your Home Assistant instance on a jailbroken Kindle device. It regularly takes a screenshot which can be polled and used as a screensaver image of the online screensaver plugin. startup: application @@ -36,24 +36,32 @@ options: SCALING: '1' GRAYSCALE_DEPTH: '8' COLOR_MODE: 'GrayScale' + DITHER: false + REMOVE_GAMMA: true PREFERS_COLOR_SCHEME: 'light' HA_BATTERY_WEBHOOK: '' + ADDITIONAL_ENV_VARS: [] schema: HA_BASE_URL: "url" HA_SCREENSHOT_URL: "str" HA_ACCESS_TOKEN: "password" - LANGUAGE: "str" - CRON_JOB: "str" - RENDERING_TIMEOUT: "int" - RENDERING_DELAY: "int" - RENDERING_SCREEN_HEIGHT: "int" - RENDERING_SCREEN_WIDTH: "int" - BROWSER_LAUNCH_TIMEOUT: "int" - ROTATION: "int" - SCALING: "float" - GRAYSCALE_DEPTH: "int" + LANGUAGE: "str?" + CRON_JOB: "str?" + RENDERING_TIMEOUT: "int?" + RENDERING_DELAY: "int?" + RENDERING_SCREEN_HEIGHT: "int?" + RENDERING_SCREEN_WIDTH: "int?" + BROWSER_LAUNCH_TIMEOUT: "int?" + ROTATION: "int?" + SCALING: "float?" + GRAYSCALE_DEPTH: "int?" COLOR_MODE: "list(GrayScale|TrueColor)?" + DITHER: "bool?" + REMOVE_GAMMA: "bool?" PREFERS_COLOR_SCHEME: "list(light|dark)?" - HA_BATTERY_WEBHOOK: "str" + HA_BATTERY_WEBHOOK: "str?" + ADDITIONAL_ENV_VARS: + - name: match(^[A-Z0-9_]+$) + value: str environment: output_path: "/output/cover.png" diff --git a/package.json b/package.json index 0844cfb..8d57485 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hass-lovelace-kindle-screensaver", - "version": "1.0.6", + "version": "1.0.7", "description": "", "main": "index.js", "scripts": { diff --git a/run.sh b/run.sh index e37d49d..d47758b 100755 --- a/run.sh +++ b/run.sh @@ -1,6 +1,6 @@ #!/usr/bin/with-contenv bashio -bashio::log.info "Starting npm server..." +bashio::log.info "Loading config..." export HA_BASE_URL="$(bashio::config 'HA_BASE_URL')" export HA_SCREENSHOT_URL=$(bashio::config 'HA_SCREENSHOT_URL') @@ -11,13 +11,29 @@ export RENDERING_TIMEOUT=$(bashio::config 'RENDERING_TIMEOUT') export RENDERING_DELAY=$(bashio::config 'RENDERING_DELAY') export RENDERING_SCREEN_HEIGHT=$(bashio::config 'RENDERING_SCREEN_HEIGHT') export RENDERING_SCREEN_WIDTH=$(bashio::config 'RENDERING_SCREEN_WIDTH') +export BROWSER_LAUNCH_TIMEOUT=$(bashio::config 'BROWSER_LAUNCH_TIMEOUT') export ROTATION=$(bashio::config 'ROTATION') export SCALING=$(bashio::config 'SCALING') export GRAYSCALE_DEPTH=$(bashio::config 'GRAYSCALE_DEPTH') export COLOR_MODE=$(bashio::config 'COLOR_MODE') +export DITHER=$(bashio::config 'DITHER') +export REMOVE_GAMMA=$(bashio::config 'REMOVE_GAMMA') +export PREFERS_COLOR_SCHEME=$(bashio::config 'PREFERS_COLOR_SCHEME') export HA_BATTERY_WEBHOOK=$(bashio::config 'HA_BATTERY_WEBHOOK') -bashio::log.info "Using base_url: ${HA_BASE_URL}" +bashio::log.info "Loading additional environment variables..." + +# Load custom environment variables +for var in $(bashio::config 'ADDITIONAL_ENV_VARS|keys'); do + name=$(bashio::config "ADDITIONAL_ENV_VARS[${var}].name") + value=$(bashio::config "ADDITIONAL_ENV_VARS[${var}].value") + bashio::log.info "Setting ${name} to ${value}" + export "${name}=${value}" +done + +bashio::log.info "Using HA_BASE_URL: ${HA_BASE_URL}" + +bashio::log.info "Starting server..." cd /app exec /usr/bin/npm start