Update display (#168)

Update display (-d) function so no empty values are displayed
This commit is contained in:
Masoko
2024-12-04 23:09:59 +02:00
committed by GitHub
parent b9cb6dbca6
commit 3baa4f81bc
2 changed files with 34 additions and 41 deletions

View File

@@ -78,7 +78,6 @@ options:
``` ```
## Installation ## Installation
### Automated ### Automated

View File

@@ -321,8 +321,7 @@ def check_all_drive_temps():
def print_measured_values(monitored_values): def print_measured_values(monitored_values):
remote_version = update.check_git_version_remote(script_dir) remote_version = update.check_git_version_remote(script_dir)
output = """:: rpi-mqtt-monitor output = """:: rpi-mqtt-monitor :: v {}
Version: {}
:: Device Information :: Device Information
Model Name: {} Model Name: {}
@@ -333,40 +332,41 @@ def print_measured_values(monitored_values):
MAC Address: {} MAC Address: {}
""".format(config.version, check_model_name(), get_manufacturer(), get_os(), hostname, get_network_ip(), get_mac_address()) """.format(config.version, check_model_name(), get_manufacturer(), get_os(), hostname, get_network_ip(), get_mac_address())
if args.service:
output += " Service Sleep Time: {} seconds\n".format(config.service_sleep_time) output += " Service Sleep Time: {} seconds\n".format(config.service_sleep_time)
if config.update: if config.update:
output += " Update Check Interval: {} seconds\n".format(config.update_check_interval) output += " Update Check Interval: {} seconds\n".format(config.update_check_interval)
output += """ # Add dynamic measured values with units
:: Measured values measured_values = {
CPU Load: {} % "CPU Load": ("cpu_load", "%"),
CPU Temp: {} °C "CPU Temp": ("cpu_temp", "°C"),
Used Space: {} % "Used Space": ("used_space", "%"),
Voltage: {} V "Voltage": ("voltage", "V"),
CPU Clock Speed: {} MHz "CPU Clock Speed": ("sys_clock_speed", "MHz"),
Swap: {} % "Swap": ("swap", "%"),
Memory: {} % "Memory": ("memory", "%"),
Online since: {} "Online since": ("uptime", ""),
Wifi Signal: {} % "Wifi Signal": ("wifi_signal", "%"),
Wifi Signal dBm: {} "Wifi Signal dBm": ("wifi_signal_dbm", "dBm"),
RPI5 Fan Speed: {} RPM "RPI5 Fan Speed": ("rpi5_fan_speed", "RPM"),
RPI Power Status: {} "RPI Power Status": ("rpi_power_status", ""),
Update: {} "Update": ("update", ""),
External Sensors: {} "External Sensors": ("ext_sensors", "")
""".format(monitored_values.get('cpu_load', ''), monitored_values.get('cpu_temp', ''), monitored_values.get('used_space', ''), monitored_values.get('voltage', ''), }
monitored_values.get('sys_clock_speed', ''), monitored_values.get('swap', ''), monitored_values.get('memory', ''), monitored_values.get('uptime', ''),
monitored_values.get('wifi_signal', ''), monitored_values.get('wifi_signal_dbm', ''), monitored_values.get('rpi5_fan_speed', ''), output += "\n:: Measured values\n"
monitored_values.get('rpi_power_status', ''), monitored_values.get('check_git_update(script_dir)', ''), monitored_values.get('ext_sensors', '')) for label, (key, unit) in measured_values.items():
if key in monitored_values:
output += f" {label}: {monitored_values[key]} {unit}\n"
drive_temps = check_all_drive_temps() drive_temps = check_all_drive_temps()
if len(drive_temps) > 0: if len(drive_temps) > 0:
for device, temp in drive_temps.items(): for device, temp in drive_temps.items():
output += f"{device.capitalize()} Temp: {temp:.2f}°C\n" output += f" {device.capitalize()} Temp: {temp:.2f}°C\n"
output += """\n:: Installation directory: \n {} output += """\n:: Installation directory :: {}
:: Release notes {}: :: Release notes {}:
{}""".format(script_dir, remote_version, get_release_notes(remote_version).strip()) {}""".format(os.path.dirname(script_dir), remote_version, get_release_notes(remote_version))
print(output) print(output)
@@ -387,18 +387,13 @@ def get_release_notes(version):
release_notes = "No release notes available" release_notes = "No release notes available"
lines = extract_text(release_notes).split('\n') lines = extract_text(release_notes).split('\n')
lines = [" * "+ line for line in lines if line.strip() != ""]
for i in range(len(lines)):
if lines[i].strip() != "":
lines[i] = "* " + lines[i]
release_notes = '\n'.join(lines) release_notes = '\n'.join(lines)
if len(release_notes) > 255: if len(release_notes) > 255:
release_notes = release_notes[:250] + " ..." release_notes = release_notes[:250] + " ..."
release_notes = "### What's Changed" + release_notes
return release_notes return release_notes
@@ -815,7 +810,6 @@ def parse_arguments():
parser.add_argument('-u', '--update', action='store_true', help='update script and config then exit', default=False) parser.add_argument('-u', '--update', action='store_true', help='update script and config then exit', default=False)
parser.add_argument('-w', '--hass_wake', action='store_true', help='display Home assistant wake on lan configuration', default=False) parser.add_argument('-w', '--hass_wake', action='store_true', help='display Home assistant wake on lan configuration', default=False)
args = parser.parse_args() args = parser.parse_args()
if args.update: if args.update: