Skip to content

Commit

Permalink
Allow additional env vars for Hass Add-On + add missing config params (
Browse files Browse the repository at this point in the history
…#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
  • Loading branch information
sibbl authored Feb 22, 2024
1 parent a921ac8 commit 27cdea6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 20 additions & 12 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hass-lovelace-kindle-screensaver",
"version": "1.0.6",
"version": "1.0.7",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
20 changes: 18 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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

0 comments on commit 27cdea6

Please sign in to comment.