2929from typing import List
3030
3131import babel .dates
32+ import requests
33+ from ping3 import ping
3234from psutil ._common import bytes2human
3335from uptime import uptime
34- import requests
3536
3637import library .config as config
3738from library .display import display
4344WLO_CARD = config .CONFIG_DATA ["config" ].get ("WLO" , "" )
4445HW_SENSORS = config .CONFIG_DATA ["config" ].get ("HW_SENSORS" , "AUTO" )
4546CPU_FAN = config .CONFIG_DATA ["config" ].get ("CPU_FAN" , "AUTO" )
47+ PING_DEST = config .CONFIG_DATA ["config" ].get ("PING" , "127.0.0.1" )
4648
4749if HW_SENSORS == "PYTHON" :
4850 if platform .system () == 'Windows' :
@@ -826,6 +828,7 @@ def stats():
826828 if theme_data is not None and last_values is not None :
827829 display_themed_line_graph (theme_data = theme_data , values = last_values )
828830
831+
829832class Weather :
830833 @staticmethod
831834 def stats ():
@@ -843,17 +846,24 @@ def stats():
843846 if 'CENTER_LENGTH' in wdescription_theme_data :
844847 center_description_length = wdescription_theme_data ['CENTER_LENGTH' ]
845848
846- activate = True if wtemperature_theme_data .get ("SHOW" ) or wfelt_theme_data .get ("SHOW" ) or wupdatetime_theme_data .get ("SHOW" ) or wdescription_theme_data .get ("SHOW" ) or whumidity_theme_data .get ("SHOW" ) else False
847-
849+ activate = True if wtemperature_theme_data .get ("SHOW" ) or wfelt_theme_data .get (
850+ "SHOW" ) or wupdatetime_theme_data .get ("SHOW" ) or wdescription_theme_data .get (
851+ "SHOW" ) or whumidity_theme_data .get ("SHOW" ) else False
852+
848853 if activate :
854+ temp = None
855+ feel = None
856+ desc = None
857+ time = None
858+ humidity = None
849859 if HW_SENSORS in ["STATIC" , "STUB" ]:
850860 temp = "17.5°C"
851861 feel = "(17.2°C)"
852862 desc = "Cloudy"
853863 time = "@15:33"
854864 humidity = "45%"
855865 if wdescription_theme_data ['CENTER_LENGTH' ]:
856- desc = "x" * center_description_length
866+ desc = "x" * center_description_length
857867 else :
858868 # API Parameters
859869 lat = config .CONFIG_DATA ['config' ].get ('WEATHER_LATITUDE' , "" )
@@ -892,10 +902,39 @@ def stats():
892902 # Display Temperature
893903 display_themed_value (theme_data = wtemperature_theme_data , value = temp )
894904 # Display Temperature Felt
895- display_themed_value (theme_data = wfelt_theme_data , value = feel )
905+ display_themed_value (theme_data = wfelt_theme_data , value = feel )
896906 # Display Update Time
897- display_themed_value (theme_data = wupdatetime_theme_data , value = time )
907+ display_themed_value (theme_data = wupdatetime_theme_data , value = time )
898908 # Display Humidity
899909 display_themed_value (theme_data = whumidity_theme_data , value = humidity )
900910 # Display Weather Description
901911 display_themed_value (theme_data = wdescription_theme_data , value = desc )
912+
913+
914+ class Ping :
915+ last_values_ping = []
916+
917+ @classmethod
918+ def stats (cls ):
919+ theme_data = config .THEME_DATA ['STATS' ]['PING' ]
920+
921+ delay = ping (dest_addr = PING_DEST , unit = "ms" )
922+
923+ save_last_value (delay , cls .last_values_ping ,
924+ theme_data ['LINE_GRAPH' ].get ("HISTORY_SIZE" , DEFAULT_HISTORY_SIZE ))
925+ # logger.debug(f"Ping delay: {delay}ms")
926+
927+ display_themed_progress_bar (theme_data ['GRAPH' ], delay )
928+ display_themed_radial_bar (
929+ theme_data = theme_data ['RADIAL' ],
930+ value = int (delay ),
931+ unit = "ms" ,
932+ min_size = 6
933+ )
934+ display_themed_value (
935+ theme_data = theme_data ['TEXT' ],
936+ value = int (delay ),
937+ unit = "ms" ,
938+ min_size = 6
939+ )
940+ display_themed_line_graph (theme_data ['LINE_GRAPH' ], cls .last_values_ping )
0 commit comments