This commit is contained in:
Hans Karlinius
2024-11-30 09:05:27 +01:00
parent 0fd9dc8a71
commit 93af4256b8
21 changed files with 24 additions and 65 deletions

View File

@@ -1,7 +1,5 @@
#!/command/with-contenv bashio
sleep 5s
if bashio::config.has_value 'autofind'; then
autofind=($(bashio::config 'autofind'))
bashio::log.info "Set AUTOFIND hub to ${autofind}"
@@ -33,7 +31,6 @@ if bashio::config.has_value 'autouse'; then
else
bashio::log.info "AUTO USE CLEAR ALL"
/usr/bin/vhclient -t "AUTO USE CLEAR ALL"
#sleep 5s
bashio::log.info "STOP USING ALL LOCAL"
/usr/bin/vhclient -t "STOP USING ALL LOCAL"
fi

View File

@@ -0,0 +1,14 @@
#!/command/with-contenv bashio
mapfile -t devices < <(/usr/bin/vh_list_devices)
for device in "${devices[@]}"; do
options=$(bashio::api.supervisor GET "/addons/self/options/config")
if [ -z $(echo $options | jq --arg device "$device" '.usbdevices[] | select(.device == ($device))') ]; then
bashio::log.info "Adding to config: ${device}"
options_updated=$(echo $options | jq --arg device "$device" '.usbdevices |= . + [{ device: ($device), use: false }]')
bashio::log.info "Options updated: ${options_updated}"
options_payload=$(echo $options_updated | jq -r '. = { options: . }')
bashio::log.info "Payload: ${options_payload}"
bashio::api.supervisor POST "/addons/self/options" $(echo $options_updated | jq -r '. = { options: . }')
fi
done

View File

@@ -0,0 +1,4 @@
#!/command/with-contenv bashio
bashio::log.info "Waiting a bit for vhclient ..."
sleep 5s

View File

@@ -0,0 +1 @@
oneshot

View File

@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/config/run

View File

@@ -1,51 +0,0 @@
#!/command/with-contenv bashio
#set -x
#test=($(bashio::config 'test'))
#test+=('one', 'two')
#bashio::config::update 'test' "${test[@]}"
#bashio::addon.option 'test' $test[@]
#TEST
#bashio::addon.option 'usbdevices' { 'name': 'one', 'use': false}
#my_array=($(bashio::config 'my_array'))
#my_array+=('one') # Add a new item to the array
#my_array+=({ 'name': 'one', 'use': false}) # Add a new item to the array
#bashio::config::update 'my_array' "${my_array[@]}"
#list1=$(/usr/bin/vhclient -t LIST)
#list2=$(eval 'grep "--" <<< "$list1"')
#bashio::log.info "${list1}"
#bashio::log.info "${list2}"
#mapfile -t devices < <(/usr/bin/vhclient -t LIST)
mapfile -t devices < <(/usr/bin/vh_list_devices)
for device in "${devices[@]}"; do
#options=$(bashio::addon.options)
options=$(bashio::api.supervisor GET "/addons/self/options/config")
gurka=$(echo $options | jq --arg device "$device" '.usbdevices[] | select(.device == ($device))')
bashio::log.info "Options: ${gurka}"
#if [[ ! " ${options}.usbdevices[*] " =~ [[:space:]]${device}[[:space:]] ]]; then
if [ -z $(echo $options | jq --arg device "$device" '.usbdevices[] | select(.device == ($device))') ]; then
bashio::log.info "Adding to config: ${device}"
options_updated=$(echo $options | jq --arg device "$device" '.usbdevices |= . + [{ device: ($device), use: false }]')
bashio::log.info "Options updated: ${options_updated}"
#payload=$(bashio::var.json options "^${new_options}")
#options_payload='{"options": ${options_updated}}'
options_payload=$(echo $options_updated | jq -r '. = { options: . }')
bashio::log.info "Payload: ${options_payload}"
bashio::api.supervisor POST "/addons/self/options" "${options_payload}"
fi
done
#options=$(bashio::addon.options)
#new_options=$(echo $options | jq .usbdevices += [{ device: 'ONE', use: false }])
#payload=$(bashio::var.json options "^${new_options}")
#bashio::api.supervisor POST "/addons/self/options" "${payload}"
curl -sH "Authorization: Bearer $SUPERVISOR_TOKEN" http://supervisor/addons/self/info | jq .data.options

View File

@@ -0,0 +1,2 @@
#!/usr/bin/with-contenv bashio
bashio::log.info "Adding selected devices"

View File

@@ -0,0 +1 @@
oneshot