From 098c9f09eabb6d7b79a1d577494c56146590d571 Mon Sep 17 00:00:00 2001 From: "Stephen M. Moraco" Date: Sat, 25 Feb 2023 19:42:00 -0700 Subject: [PATCH] Final updates, bump version for release --- ChangeLog | 7 ++---- ISP-RPi-mqtt-daemon.py | 52 +++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1af0b68..dbc7900 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,6 @@ # ChangeLog ----- preparing next update ------- v1.7.5 +Sat, 25 Feb 2023 19:36:42 -0700 v1.8.0 - Update README.md and requirements.txt to reflect use of Python `apt` library - Add reporting of pending os updates (#71) See `ux_updates` @@ -9,10 +9,7 @@ - Incorporate network usage from @mcarlosro (#47) See `tx_data` and `rx_data` for each network IF - Incorporate remote restart from @hobbypunk90 (#77, #80). Docs in README - Filter @suffix from network interface names (happens when run from container) (#46) - -This version has a new requirement that `python3-apt` be installed. If it is not installed -then you will see `ux_updates` reported as (-1). Note: for **Linux Arch** users this package is NOT avail. so you will always see (-1) for pending updates. - +- Add new RMTECTRL.md advising on how to set up control over your RPi Sat, 18 Feb 2023 15:36:08 -0700 v1.7.4 diff --git a/ISP-RPi-mqtt-daemon.py b/ISP-RPi-mqtt-daemon.py index d88001b..362b32f 100755 --- a/ISP-RPi-mqtt-daemon.py +++ b/ISP-RPi-mqtt-daemon.py @@ -27,10 +27,14 @@ import time import requests from urllib3.exceptions import InsecureRequestWarning -import apt +apt_available = True +try: + import apt +except ImportError: + apt_available = False -script_version = "1.7.5" +script_version = "1.8.0" script_name = 'ISP-RPi-mqtt-daemon.py' script_info = '{} v{}'.format(script_name, script_version) project_name = 'RPi Reporter MQTT2HA Daemon' @@ -367,6 +371,9 @@ def getDaemonReleases(): rpi_cpuload15 = '' rpi_update_count = 0 +if apt_available == False: + rpi_update_count = -1 # if packaging system not avail. report -1 + # Time for network transfer calculation previous_time = time.time() @@ -636,10 +643,7 @@ def getNetworkIFsUsingIP(ip_cmd): if len(trimmedLine) > 0: lineParts = trimmedLine.split() interfaceName = lineParts[1].replace(':', '') - # if interface is within a docker container then we have - # something like: eth0@if77 let's strip the @if77 part (comment in issue #46) - if '@' in interfaceName: - interfaceName = interfaceName.split('@')[0] + # if interface is within a container then we have eth0@if77 interfaceNames.append(interfaceName) print_line('interfaceNames=[{}]'.format(interfaceNames), debug=True) @@ -1152,15 +1156,16 @@ def getLastInstallDate(): def getNumberOfAvailableUpdates(): global rpi_update_count global update_last_fetch_time - cache = apt.Cache() - cache.open(None) - cache.upgrade() - changes = cache.get_changes() - print_line('APT changes=[{}]'.format(changes), debug=True) - print_line('APT Avail Updates: ({})'.format(len(changes)), info=True) - # return str(cache.get_changes().len()) - rpi_update_count = len(changes) - update_last_fetch_time = time.time() + if apt_available: + cache = apt.Cache() + cache.open(None) + cache.upgrade() + changes = cache.get_changes() + print_line('APT changes=[{}]'.format(changes), debug=True) + print_line('APT Avail Updates: ({})'.format(len(changes)), info=True) + # return str(cache.get_changes().len()) + rpi_update_count = len(changes) + update_last_fetch_time = time.time() # get our hostnames so we can setup MQTT getHostnames() @@ -1172,7 +1177,8 @@ def getNumberOfAvailableUpdates(): getLinuxRelease() getLinuxVersion() getFileSystemDrives() -getNumberOfAvailableUpdates() +if apt_available: + getNumberOfAvailableUpdates() # ----------------------------------------------------------------------------- # timer and timer funcs for ALIVE MQTT Notices handling @@ -1369,12 +1375,19 @@ def isAliveTimerRunning(): for [command, _] in commands.items(): #print_line('- REGISTER command: [{}]'.format(command), debug=True) + iconName = 'mdi:gesture-tap' + if 'reboot' in command: + iconName = 'mdi:restart' + elif 'shutdown' in command: + iconName = 'mdi:power-sleep' + elif 'service' in command: + iconName = 'mdi:cog-counterclockwise' detectorValues.update({ command: dict( title='RPi Command {} {}'.format(rpi_hostname, command), topic_category='button', no_title_prefix='yes', - icon='mdi:gesture-tap', + icon=iconName, command = command, command_topic = '{}/{}'.format(base_command_topic, command) ) @@ -1785,8 +1798,9 @@ def afterMQTTConnect(): if timeNow > daemon_last_fetch_time + kVersionCheckIntervalInSeconds: getDaemonReleases() # and load them! - if timeNow > update_last_fetch_time + kUpdateCheckIntervalInSeconds: - getNumberOfAvailableUpdates()() # and count them! + if apt_available: + if timeNow > update_last_fetch_time + kUpdateCheckIntervalInSeconds: + getNumberOfAvailableUpdates()() # and count them! finally: # cleanup used pins... just because we like cleaning up after us