From 1b127ecac3791aca87ebfa7f4357cd270f76c87e Mon Sep 17 00:00:00 2001 From: Andre Cirne Date: Sat, 20 Apr 2024 21:47:48 +0100 Subject: [PATCH] Add sent bytes and fix server id --- speedtest/rootfs/etc/services.d/speedtest/run | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/speedtest/rootfs/etc/services.d/speedtest/run b/speedtest/rootfs/etc/services.d/speedtest/run index e8167a8..74b5a22 100755 --- a/speedtest/rootfs/etc/services.d/speedtest/run +++ b/speedtest/rootfs/etc/services.d/speedtest/run @@ -27,9 +27,17 @@ function post_result() { 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}}" + 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}}" + fi - 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}}" - bashio::api.supervisor POST "/core/api/states/sensor.speedtest_$sensor" "$data" bashio::log.info "$friendlyname updated" @@ -47,7 +55,9 @@ fi bashio::log.debug "Speedtest output: ${RESULT}" export down_load_speed=$(printf %.2f "$(($(echo $RESULT | jq .download.bandwidth)*8/10000))e-2") +export down_bytes=$(echo $RESULT | jq .download.bytes) export up_load_speed=$(printf %.2f "$(($(echo $RESULT | jq .upload.bandwidth)*8/10000))e-2") +export up_bytes=$(echo $RESULT | jq .upload.bytes) export ping_latency=$(echo $RESULT | jq .ping.latency) export used_server_id=$(echo $RESULT | jq .server.id) export used_server_name=$(echo $RESULT | jq .server.location) # This is exact the same behaviour of the native HomeAssistant speedtest @@ -62,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 -post_result "upload" "Mbit/s" "Speedtest Upload" $up_load_speed $used_server_id $used_server_name $used_server_country +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