Skip to content

Commit

Permalink
Remore friendly-name #16
Browse files Browse the repository at this point in the history
  • Loading branch information
MrSuicideParrot committed Apr 20, 2024
1 parent 1b127ec commit ca8859e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions speedtest/rootfs/etc/services.d/speedtest/run
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ fi
function post_result() {
local sensor=${1}
local unitmeasure=${2}
local friendlyname=${3}
local state=${4}
local serverid=${5}
local servername=${6}
local servercountry=${7}
local bytes=${8}


if "$sensor" == "ping"; then
local data="{\"state\":$state, \"attributes\":{\"state_class\":\"measurement\",\"unit_of_measurement\":\"$unitmeasure\",\"friendly_name\":\"$friendlyname\",\"icon\":\"mdi:speedometer\",\"server_name\":$servername,\"server_country\":$servercountry,\"server_id\":\"$serverid\"}}"
elif "$sensor" == "download"; then
local data="{\"state\":$state, \"attributes\":{\"state_class\":\"measurement\",\"unit_of_measurement\":\"$unitmeasure\",\"friendly_name\":\"$friendlyname\",\"icon\":\"mdi:speedometer\",\"server_name\":$servername,\"server_country\":$servercountry,\"server_id\":\"$serverid\",\"bytes_received\":$bytes}}"
local state=${3}
local serverid=${4}
local servername=${5}
local servercountry=${6}


if [ "$sensor" = "ping" ]; then
local data="{\"state\":$state, \"attributes\":{\"state_class\":\"measurement\",\"unit_of_measurement\":\"$unitmeasure\",\"icon\":\"mdi:speedometer\",\"server_name\":$servername,\"server_country\":$servercountry,\"server_id\":\"$serverid\"}}"
elif [ "$sensor" = "download" ]; then
local bytes=${7}
local data="{\"state\":$state, \"attributes\":{\"state_class\":\"measurement\",\"unit_of_measurement\":\"$unitmeasure\",\"icon\":\"mdi:speedometer\",\"server_name\":$servername,\"server_country\":$servercountry,\"server_id\":\"$serverid\",\"bytes_received\":$bytes}}"
else
local data="{\"state\":$state, \"attributes\":{\"state_class\":\"measurement\",\"unit_of_measurement\":\"$unitmeasure\",\"friendly_name\":\"$friendlyname\",\"icon\":\"mdi:speedometer\",\"server_name\":$servername,\"server_country\":$servercountry,\"server_id\":\"$serverid\",\"bytes_sent\":$bytes}}"
local bytes=${7}
local data="{\"state\":$state, \"attributes\":{\"state_class\":\"measurement\",\"unit_of_measurement\":\"$unitmeasure\",\"icon\":\"mdi:speedometer\",\"server_name\":$servername,\"server_country\":$servercountry,\"server_id\":\"$serverid\",\"bytes_sent\":$bytes}}"
fi

bashio::api.supervisor POST "/core/api/states/sensor.speedtest_$sensor" "$data"

bashio::log.info "$friendlyname updated"
bashio::log.info "$sensor updated"
}

bashio::log.info "Starting speed test"
Expand Down Expand Up @@ -72,6 +72,6 @@ bashio::log.info "Server id: $used_server_id"
bashio::log.info "Server country: $used_server_country"
bashio::log.info "--------- ---------"

post_result "download" "Mbit/s" "Speedtest Download" $down_load_speed $used_server_id $used_server_name $used_server_country $down_bytes
post_result "upload" "Mbit/s" "Speedtest Upload" $up_load_speed $used_server_id $used_server_name $used_server_country $up_bytes
post_result "ping" "ms" "Speedtest Ping" $ping_latency $used_server_id $used_server_name $used_server_country
post_result "download" "Mbit/s" $down_load_speed $used_server_id $used_server_name $used_server_country $down_bytes
post_result "upload" "Mbit/s" $up_load_speed $used_server_id $used_server_name $used_server_country $up_bytes
post_result "ping" "ms" $ping_latency $used_server_id $used_server_name $used_server_country

0 comments on commit ca8859e

Please sign in to comment.