This commit is contained in:
Michael
2021-11-10 16:49:05 +00:00
commit 7cb3d49962
69 changed files with 5622 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
# Home Assistant Community Add-on: Example
[![Release][release-shield]][release] ![Project Stage][project-stage-shield] ![Project Maintenance][maintenance-shield]
[![Discord][discord-shield]][discord] [![Community Forum][forum-shield]][forum]
[![Sponsor Frenck via GitHub Sponsors][github-sponsors-shield]][github-sponsors]
[![Support Frenck on Patreon][patreon-shield]][patreon]
Example add-on by Community Home Assistant add-ons.
## About
This is an example add-on for Home Assistant. When started, it displays a
random quote every 5 seconds.
It shows off several features and structures like:
- Full blown GitHub repository.
- General Dockerfile structure and setup.
- The use of the `config.json` and `build.json` files.
- General shell scripting structure (`run.sh`).
- Quality assurance using CodeClimate.
- Continuous integration and deployment using GitLab.
- Usage of the Community Home Assistant Add-ons build environment.
- Small use of the Bash function library in our base images.
- The use of Docker label schema.
{% if channel == "edge" %}
## WARNING! THIS IS AN EDGE VERSION!
This Home Assistant Add-ons repository contains edge builds of add-ons.
Edge builds add-ons are based upon the latest development version.
- They may not work at all.
- They might stop working at any time.
- They could have a negative impact on your system.
This repository was created for:
- Anybody willing to test.
- Anybody interested in trying out upcoming add-ons or add-on features.
- Developers.
If you are more interested in stable releases of our add-ons:
<https://github.com/hassio-addons/repository>
{% endif %}
{% if channel == "beta" %}
## WARNING! THIS IS A BETA VERSION!
This Home Assistant Add-ons repository contains beta releases of add-ons.
- They might stop working at any time.
- They could have a negative impact on your system.
This repository was created for:
- Anybody willing to test.
- Anybody interested in trying out upcoming add-ons or add-on features.
If you are more interested in stable releases of our add-ons:
<https://github.com/hassio-addons/repository>
{% endif %}
[discord-shield]: https://img.shields.io/discord/478094546522079232.svg
[discord]: https://discord.me/hassioaddons
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
[forum]: https://community.home-assistant.io?u=frenck
[github-sponsors-shield]: https://frenck.dev/wp-content/uploads/2019/12/github_sponsor.png
[github-sponsors]: https://github.com/sponsors/frenck
[maintenance-shield]: https://img.shields.io/maintenance/yes/2021.svg
[patreon-shield]: https://frenck.dev/wp-content/uploads/2019/12/patreon.png
[patreon]: https://www.patreon.com/frenck
[project-stage-shield]: https://img.shields.io/badge/project%20stage-production%20ready-brightgreen.svg
[release-shield]: https://img.shields.io/badge/version-{{ version }}-blue.svg
[release]: {{ repo }}/tree/{{ version }}

View File

@@ -0,0 +1,132 @@
# Home Assistant Community Add-on: Example
This is an example add-on for Home Assistant. When started, it displays a
random quote every 5 seconds.
It shows off several features and structures like:
- Full blown GitHub repository.
- General Dockerfile structure and setup.
- The use of the `config.yaml` and `build.yaml` files.
- General shell scripting structure (`run.sh`).
- Quality assurance using CodeClimate.
- Continuous integration and deployment using GitLab.
- Usage of the Community Home Assistant Add-ons build environment.
- Small use of the Bash function library in our base images.
- The use of Docker label schema.
## Installation
The installation of this add-on is pretty straightforward and not different in
comparison to installing any other Home Assistant add-on.
1. Search for the "Example" add-on in the Supervisor add-on store and install it.
1. Start the "Example" add-on.
1. Check the logs of the "Example" add-on to see it in action.
## Configuration
Eventought this add-on is just an example add-on, it does come with some
configuration options to play around with.
**Note**: _Remember to restart the add-on when the configuration is changed._
Example add-on configuration:
```yaml
log_level: info
seconds_between_quotes: 5
```
### Option: `log_level`
The `log_level` option controls the level of log output by the add-on and can
be changed to be more or less verbose, which might be useful when you are
dealing with an unknown issue. Possible values are:
- `trace`: Show every detail, like all called internal functions.
- `debug`: Shows detailed debug information.
- `info`: Normal (usually) interesting events.
- `warning`: Exceptional occurrences that are not errors.
- `error`: Runtime errors that do not require immediate action.
- `fatal`: Something went terribly wrong. Add-on becomes unusable.
Please note that each level automatically includes log messages from a
more severe level, e.g., `debug` also shows `info` messages. By default,
the `log_level` is set to `info`, which is the recommended setting unless
you are troubleshooting.
### Option: `seconds_between_quotes`
Sets the number of seconds between the output of each quote. The value
must be between `1` and `120` seconds. This value is set to `5` seconds by
default.
## Changelog & Releases
This repository keeps a change log using [GitHub's releases][releases]
functionality.
Releases are based on [Semantic Versioning][semver], and use the format
of `MAJOR.MINOR.PATCH`. In a nutshell, the version will be incremented
based on the following:
- `MAJOR`: Incompatible or major changes.
- `MINOR`: Backwards-compatible new features and enhancements.
- `PATCH`: Backwards-compatible bugfixes and package updates.
## Support
Got questions?
You have several options to get them answered:
- The [Home Assistant Community Add-ons Discord chat server][discord] for add-on
support and feature requests.
- The [Home Assistant Discord chat server][discord-ha] for general Home
Assistant discussions and questions.
- The Home Assistant [Community Forum][forum].
- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit]
You could also [open an issue here][issue] GitHub.
## Authors & contributors
The original setup of this repository is by [Franck Nijhof][frenck].
For a full list of all authors and contributors,
check [the contributor's page][contributors].
## License
MIT License
Copyright (c) 2017-2021 Franck Nijhof
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
[contributors]: https://github.com/hassio-addons/addon-example/graphs/contributors
[discord-ha]: https://discord.gg/c5DvZ4e
[discord]: https://discord.me/hassioaddons
[forum]: https://community.home-assistant.io/t/repository-community-hass-io-add-ons/24705?u=frenck
[frenck]: https://github.com/frenck
[issue]: https://github.com/hassio-addons/addon-example/issues
[reddit]: https://reddit.com/r/homeassistant
[releases]: https://github.com/hassio-addons/addon-example/releases
[semver]: http://semver.org/spec/v2.0.0.html

View File

@@ -0,0 +1,40 @@
ARG BUILD_FROM=ghcr.io/hassio-addons/base/amd64:10.2.0
# hadolint ignore=DL3006
FROM ${BUILD_FROM}
# Copy root filesystem
COPY rootfs /
# Setup base
RUN apk add --no-cache \
coreutils=8.32-r2 \
wget=1.21.1-r1
# Build arguments
ARG BUILD_ARCH
ARG BUILD_DATE
ARG BUILD_DESCRIPTION
ARG BUILD_NAME
ARG BUILD_REF
ARG BUILD_REPOSITORY
ARG BUILD_VERSION
# Labels
LABEL \
io.hass.name="${BUILD_NAME}" \
io.hass.description="${BUILD_DESCRIPTION}" \
io.hass.arch="${BUILD_ARCH}" \
io.hass.type="addon" \
io.hass.version=${BUILD_VERSION} \
maintainer="Franck Nijhof <frenck@addons.community>" \
org.opencontainers.image.title="${BUILD_NAME}" \
org.opencontainers.image.description="${BUILD_DESCRIPTION}" \
org.opencontainers.image.vendor="Home Assistant Community Add-ons" \
org.opencontainers.image.authors="Franck Nijhof <frenck@addons.community>" \
org.opencontainers.image.licenses="MIT" \
org.opencontainers.image.url="https://addons.community" \
org.opencontainers.image.source="https://github.com/${BUILD_REPOSITORY}" \
org.opencontainers.image.documentation="https://github.com/${BUILD_REPOSITORY}/blob/main/README.md" \
org.opencontainers.image.created=${BUILD_DATE} \
org.opencontainers.image.revision=${BUILD_REF} \
org.opencontainers.image.version=${BUILD_VERSION}

View File

@@ -0,0 +1,7 @@
---
build_from:
aarch64: ghcr.io/hassio-addons/base/aarch64:10.2.0
amd64: ghcr.io/hassio-addons/base/amd64:10.2.0
armhf: ghcr.io/hassio-addons/base/armhf:10.2.0
armv7: ghcr.io/hassio-addons/base/armv7:10.2.0
i386: ghcr.io/hassio-addons/base/i386:10.2.0

View File

@@ -0,0 +1,19 @@
---
name: Example
version: dev
slug: example
description: Example add-on by Community Home Assistant Add-ons
url: https://github.com/hassio-addons/addon-example
init: false
arch:
- aarch64
- amd64
- armhf
- armv7
- i386
options:
log_level: info
seconds_between_quotes: 5
schema:
log_level: list(trace|debug|info|notice|warning|error|fatal)
seconds_between_quotes: int(1,120)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 130 KiB

View File

@@ -0,0 +1,8 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Home Assistant Community Add-on: Example
# ==============================================================================
if -n { s6-test $# -ne 0 }
if -n { s6-test ${1} -eq 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Example
# Runs example1 script
# ==============================================================================
bashio::log.info "Starting Example1..."
exec /usr/bin/example1.sh

View File

@@ -0,0 +1,8 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Home Assistant Community Add-on: Example
# ==============================================================================
if -n { s6-test $# -ne 0 }
if -n { s6-test ${1} -eq 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Example
# Runs example2 script
# ==============================================================================
bashio::log.info "Starting Example2..."
exec /usr/bin/example2.sh

View File

@@ -0,0 +1,115 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Example
#
# Example add-on for Home Assistant.
# This add-on displays a random quote every X seconds.
# ==============================================================================
# ------------------------------------------------------------------------------
# Get a random quote from quotationspage.com
#
# Arguments:
# None
# Returns:
# String with the quote
# ------------------------------------------------------------------------------
get_quote_online() {
local number
local html
local quote
bashio::log.trace "${FUNCNAME[0]}"
number=$(( ( RANDOM % 999 ) + 1 ))
html=$(wget -q -O - "http://www.quotationspage.com/quote/${number}.html")
quote=$(grep -e "<dt>" -e "</dd>" <<< "${html}" \
| awk -F'[<>]' '{
if($2 ~ /dt/)
{ print $3 }
else if($4 ~ /b/)
{ print "-- " $7 " n(" $19 ")"}
}'
)
echo "${quote}"
}
# ------------------------------------------------------------------------------
# Get a random quote from a prefined set of quotes
#
# Arguments:
# None
# Returns:
# String with the quote
# ------------------------------------------------------------------------------
get_quote_offline() {
local -i number
local -a quotes
bashio::log.trace "${FUNCNAME[0]}"
quotes+=("Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better.\\n -Samuel Beckett")
quotes+=("Never give up, for that is just the place and time that the tide will turn.\\n -Harriet Beecher Stowe")
quotes+=("Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.\\n -Thomas A. Edison")
quotes+=("Life isn't about getting and having, it's about giving and being.\\n -Kevin Kruse")
quotes+=("Strive not to be a success, but rather to be of value.\\n -Albert Einstein")
quotes+=("You miss 100% of the shots you don't take.\\n -Wayne Gretzky")
quotes+=("People who are unable to motivate themselves must be content with mediocrity, no matter how impressive their other talents. \\n -Andrew Carnegie")
quotes+=("Design is not just what it looks like and feels like. Design is how it works.\\n -Steve Jobs")
quotes+=("Only those who dare to fail greatly can ever achieve greatly.\\n -Robert F. Kennedy")
quotes+=("All our dreams can come true, if we have the courage to pursue them.\\n -Walt Disney")
quotes+=("Success consists of going from failure to failure without loss of enthusiasm.\\n -Winston Churchill")
number=$(( ( RANDOM % 11 ) + 1 ))
echo "${quotes[$number]}"
}
# ------------------------------------------------------------------------------
# Displays a random quote
#
# Arguments:
# None
# Returns:
# String with the quote
# -----------------------------------------------------------------------------
display_quote() {
local quote
local timestamp
bashio::log.trace "${FUNCNAME[0]}"
if wget -q --spider http://www.quotationspage.com; then
quote=$(get_quote_online)
else
bashio::log.notice \
'Could not connect to quotationspage.com, using an offline quote'
quote=$(get_quote_offline)
fi
# shellcheck disable=SC2001
quote=$(sed 's/n()//g' <<< "${quote}" | xargs -0 echo | fmt -40)
timestamp=$(date +"%T")
bashio::log.info "Random quote loaded @ ${timestamp}"
echo -e "${quote}"
}
# ==============================================================================
# RUN LOGIC
# ------------------------------------------------------------------------------
main() {
local sleep
bashio::log.trace "${FUNCNAME[0]}"
sleep=$(bashio::config 'seconds_between_quotes')
bashio::log.info "Seconds between each quotes is set to: ${sleep}"
while true; do
display_quote
sleep "${sleep}"
done
}
main "$@"

View File

@@ -0,0 +1,15 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Home Assistant Community Add-on: Example
#
# Example add-on for Home Assistant.
# ------------------------------------------------------------------------------
main() {
bashio::log.trace "${FUNCNAME[0]}"
while true; do
echo "Second Script Output"
sleep 10
done
}
main "$@"

View File

@@ -0,0 +1,10 @@
---
configuration:
log_level:
name: Log level
description: The amount of logging the add-on should do.
seconds_between_quotes:
name: Seconds between quotes
description: >-
The number of seconds the add-on waits until showing a new quote in the
add-on log.