Allow to fetch location via API

This commit is contained in:
Max Winterstein
2022-03-29 23:34:54 +02:00
parent 296fc72dcf
commit 646de6abad
5 changed files with 36 additions and 12 deletions
@@ -5,7 +5,10 @@
#
# This needs to be sourced ($ source $0)
CONFIG=$(curl -s -H "Authorization: Bearer ${SUPERVISOR_TOKEN}" -H "Content-Type: application/json" http://supervisor/core/api/config)
LAT=$(echo $CONFIG | jq '.latitude')
LON=$(echo $CONFIG | jq '.longitude')
ELE=$(echo $CONFIG | jq '.elevation')
# TODO: Find a way to use bashio and source together
@@ -18,6 +21,12 @@ fi
# thx https://stackoverflow.com/a/48513046/635876
while read -rd $'' line
do
if [[ $line == *"HOMEASSISTANT_LATITUDE" ]] || [[ $line == *"HOMEASSISTANT_LONGITUDE" ]] || [[ $line == *"HOMEASSISTANT_ELEVATION" ]]; then
line=$(echo $line | sed "s/HOMEASSISTANT_LATITUDE/$LAT/")
line=$(echo $line | sed "s/HOMEASSISTANT_LONGITUDE/$LON/")
line=$(echo $line | sed "s/HOMEASSISTANT_ELEVATION/$ELE/")
fi
# echo $line
export "$line"
done < <(jq -r <<<"$(cat /data/options.json)" \
'to_entries|map("\(.key)=\(.value)\u0000")[]')