mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-01-22 20:46:28 +01:00
Dev version
This commit is contained in:
16
enedisgateway2mqtt_dev/rootfs/entrypoint.sh
Normal file
16
enedisgateway2mqtt_dev/rootfs/entrypoint.sh
Normal file
@@ -0,0 +1,16 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "Starting..."
|
||||
|
||||
####################
|
||||
# Starting scripts #
|
||||
####################
|
||||
|
||||
for SCRIPTS in scripts/*; do
|
||||
[ -e "$SCRIPTS" ] || continue
|
||||
echo "$SCRIPTS: executing"
|
||||
chown $(id -u):$(id -g) $SCRIPTS
|
||||
chmod a+x $SCRIPTS
|
||||
sed -i 's|/usr/bin/with-contenv bashio|/usr/bin/env bashio|g' $SCRIPTS || true
|
||||
./$SCRIPTS || echo "$SCRIPTS: exiting $?"
|
||||
done
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
# If dockerfile failed install manually
|
||||
if [ ! -f "/usr/bin/bashio" ]; then
|
||||
echo "Bashio does not exist, executing script"
|
||||
(
|
||||
# Remove errors on apt-get
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
################
|
||||
# Install apps #
|
||||
################
|
||||
apt-get clean &&
|
||||
apt-get update &&
|
||||
apt-get install -yq --no-install-recommends \
|
||||
jq \
|
||||
curl \
|
||||
yamllint
|
||||
|
||||
###################
|
||||
# Install bashio #
|
||||
##################
|
||||
BASHIO_VERSION=0.13.1
|
||||
mkdir -p /tmp/bashio
|
||||
curl -L -f -s "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" |
|
||||
tar -xzf - --strip 1 -C /tmp/bashio
|
||||
mv /tmp/bashio/lib /usr/lib/bashio
|
||||
ln -s /usr/lib/bashio/bashio /usr/bin/bashio
|
||||
rm -rf /tmp/bashio
|
||||
) >/dev/null
|
||||
echo "Bashio installed"
|
||||
fi
|
||||
39
enedisgateway2mqtt_dev/rootfs/scripts/00-banner.sh
Normal file
39
enedisgateway2mqtt_dev/rootfs/scripts/00-banner.sh
Normal file
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Displays a simple add-on banner on startup
|
||||
# ==============================================================================
|
||||
|
||||
if bashio::supervisor.ping; then
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue " Add-on: $(bashio::addon.name)"
|
||||
bashio::log.blue " $(bashio::addon.description)"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
bashio::log.blue " Add-on version: $(bashio::addon.version)"
|
||||
if bashio::var.true "$(bashio::addon.update_available)"; then
|
||||
bashio::log.magenta ' There is an update available for this add-on!'
|
||||
bashio::log.magenta \
|
||||
" Latest add-on version: $(bashio::addon.version_latest)"
|
||||
bashio::log.magenta ' Please consider upgrading as soon as possible.'
|
||||
else
|
||||
bashio::log.green ' You are running the latest version of this add-on.'
|
||||
fi
|
||||
|
||||
bashio::log.blue " System: $(bashio::info.operating_system)" \
|
||||
" ($(bashio::info.arch) / $(bashio::info.machine))"
|
||||
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
|
||||
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
|
||||
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue \
|
||||
' Please, share the above information when looking for help'
|
||||
bashio::log.blue \
|
||||
' or support in, e.g., GitHub, forums'
|
||||
bashio::log.green \
|
||||
' https://github.com/alexbelgium/hassio-addons'
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
fi
|
||||
41
enedisgateway2mqtt_dev/rootfs/scripts/00-global_var.sh
Normal file
41
enedisgateway2mqtt_dev/rootfs/scripts/00-global_var.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
###################################
|
||||
# Export all addon options as env #
|
||||
###################################
|
||||
|
||||
# For all keys in options.json
|
||||
JSONSOURCE="/data/options.json"
|
||||
|
||||
# Export keys as env variables
|
||||
# echo "All addon options were exported as variables"
|
||||
mapfile -t arr < <(jq -r 'keys[]' ${JSONSOURCE})
|
||||
for KEYS in ${arr[@]}; do
|
||||
# export key
|
||||
VALUE=$(jq .$KEYS ${JSONSOURCE})
|
||||
export ${KEYS}=${VALUE//[\"\']/} &>/dev/null
|
||||
done
|
||||
|
||||
################
|
||||
# Set timezone #
|
||||
################
|
||||
if [ ! -z "TZ" ] && [ -f /etc/localtime ]; then
|
||||
if [ -f /usr/share/zoneinfo/$TZ ]; then
|
||||
echo "Timezone set from $(cat /etc/timezone) to $TZ"
|
||||
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ >/etc/timezone
|
||||
else
|
||||
echo "WARNING : Timezone $TZ is invalid, it will be kept to default value of $(cat /etc/timezone)"
|
||||
fi
|
||||
fi
|
||||
|
||||
############
|
||||
# Set user #
|
||||
############
|
||||
|
||||
if [ ! -z "PUID" ] && [ ! -z "GUID" ]; then
|
||||
echo "Custom user defined : $PUID:$GUID"
|
||||
PUID=${PUID:-911}
|
||||
PGID=${PGID:-911}
|
||||
groupmod -o -g "$PGID" abc
|
||||
usermod -o -u "$PUID" abc
|
||||
fi
|
||||
76
enedisgateway2mqtt_dev/rootfs/scripts/99-run.sh
Normal file
76
enedisgateway2mqtt_dev/rootfs/scripts/99-run.sh
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env bashio
|
||||
|
||||
##################
|
||||
# INITIALIZATION #
|
||||
##################
|
||||
|
||||
# Where is the config
|
||||
CONFIGSOURCE=$(bashio::config "CONFIG_LOCATION")
|
||||
DATABASESOURCE="$(dirname "${CONFIGSOURCE}")/enedisgateway.db"
|
||||
|
||||
# Make sure folder exist
|
||||
mkdir -p "$(dirname "${CONFIGSOURCE}")"
|
||||
mkdir -p "$(dirname "${DATABASESOURCE}")"
|
||||
|
||||
# Check absence of config file
|
||||
if [ -f /data/config.yaml ] && [ ! -L /data/config.yaml ]; then
|
||||
bashio::log.warning "A current config was found in /data, it is backuped to ${CONFIGSOURCE}.bak"
|
||||
mv /data/config.yaml $CONFIGSOURCE.bak
|
||||
fi
|
||||
|
||||
# Check if config file is there, or create one from template
|
||||
if [ -f $CONFIGSOURCE ]; then
|
||||
# Create symlink if not existing yet
|
||||
[ ! -L /data/config.yaml ] && ln -sf $CONFIGSOURCE /data
|
||||
bashio::log.info "Using config file found in $CONFIGSOURCE"
|
||||
|
||||
# Check if yaml is valid
|
||||
EXIT_CODE=0
|
||||
yamllint -d relaxed --no-warnings $CONFIGSOURCE &> ERROR || EXIT_CODE=$?
|
||||
if [ $EXIT_CODE = 0 ]; then
|
||||
echo "Config file is a valid yaml"
|
||||
else
|
||||
cat ERROR
|
||||
bashio::log.fatal "Config file has an invalid yaml format. Please check the file in $CONFIGSOURCE. Errors list above. You can check yaml validity with the online tool yamllint.com"
|
||||
bashio::exit.nok
|
||||
fi
|
||||
else
|
||||
# Create symlink for addon to create config
|
||||
touch ${CONFIGSOURCE}
|
||||
ln -sf $CONFIGSOURCE /data
|
||||
rm $CONFIGSOURCE
|
||||
# Need to restart
|
||||
bashio::log.fatal "Config file not found. The addon will create a new one, then stop. Please customize the file in $CONFIGSOURCE before restarting."
|
||||
fi
|
||||
|
||||
# Remove previous link or file
|
||||
[ -f /data/enedisgateway.db ] && rm /data/enedisgateway.db
|
||||
|
||||
# Check if database is here or create symlink
|
||||
if [ -f $DATABASESOURCE ]; then
|
||||
# Create symlink if not existing yet
|
||||
ln -sf ${DATABASESOURCE} /data && echo "creating symlink"
|
||||
bashio::log.info "Using database file found in $DATABASESOURCE"
|
||||
else
|
||||
# Create symlink for addon to create database
|
||||
touch ${DATABASESOURCE}
|
||||
ln -sf $DATABASESOURCE /data
|
||||
rm $DATABASESOURCE
|
||||
fi
|
||||
|
||||
##############
|
||||
# Launch App #
|
||||
##############
|
||||
echo " "
|
||||
bashio::log.info "Starting the app"
|
||||
echo " "
|
||||
|
||||
# Test mode
|
||||
if [ $TZ = "test" ]; then
|
||||
echo "secret mode found, launching script in /config/test.sh"
|
||||
cd /config
|
||||
chmod 777 test.sh
|
||||
./test.sh
|
||||
fi
|
||||
|
||||
python -u /app/main.py || bashio::log.fatal "The app has crashed. Are you sure you entered the correct config options?"
|
||||
63
enedisgateway2mqtt_dev/rootfs/templates/config.yaml
Normal file
63
enedisgateway2mqtt_dev/rootfs/templates/config.yaml
Normal file
@@ -0,0 +1,63 @@
|
||||
##########
|
||||
# GLOBAL #
|
||||
##########
|
||||
debug: false
|
||||
|
||||
####################
|
||||
## MQTT ##
|
||||
####################
|
||||
mqtt:
|
||||
host: MOSQUITO_SERVER # MANDATORY
|
||||
port: 1883
|
||||
username: ""
|
||||
password: ""
|
||||
prefix: enedis_gateway
|
||||
client_id: enedis_gateway
|
||||
retain: true
|
||||
qos: 0
|
||||
|
||||
####################
|
||||
## Home assistant ##
|
||||
####################
|
||||
home_assistant:
|
||||
discovery: false
|
||||
discovery_prefix: homeassistant
|
||||
card_myenedis: false
|
||||
|
||||
###############
|
||||
## Influx DB ##
|
||||
###############
|
||||
#influxdb:
|
||||
# host: MY_INFLUXDB_SERVER
|
||||
# port: 8086
|
||||
# token: MY_TOKEN
|
||||
# org: MY_ORG
|
||||
# bucket: MY_BUCKET
|
||||
|
||||
####################
|
||||
## ENEDIS GATEWAY ##
|
||||
####################
|
||||
enedis_gateway:
|
||||
PDL_1: # MANDATORY
|
||||
token: PDL_1_TOKEN # MANDATORY
|
||||
plan: BASE # BASE or HP/HC
|
||||
consumption: true
|
||||
consumption_detail: true
|
||||
consumption_price_hc: 0
|
||||
consumption_price_hp: 0
|
||||
consumption_price_base: 0
|
||||
production: false
|
||||
production_detail: false
|
||||
# offpeak_hours: "" # USE ONLY IF YOU WANT OVERLOAD DEFAULT VALUE, Format : 22h36-00h10;01h00-06h00
|
||||
addresses: true
|
||||
# PDL_2:
|
||||
# token: PDL_2_TOKEN
|
||||
# plan: HP/HC
|
||||
# consumption: true
|
||||
# consumption_detail: true
|
||||
# consumption_price_hc: 0.1781
|
||||
# consumption_price_hp: 0.1337
|
||||
# consumption_price_base: 0.1781
|
||||
# production: false
|
||||
# production_detail: false
|
||||
# addresses: true
|
||||
Reference in New Issue
Block a user