Skip to content

Commit

Permalink
Final updates, bump version for release
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Feb 26, 2023
1 parent 008b265 commit 098c9f0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
7 changes: 2 additions & 5 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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

Expand Down
52 changes: 33 additions & 19 deletions ISP-RPi-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -1172,7 +1177,8 @@ def getNumberOfAvailableUpdates():
getLinuxRelease()
getLinuxVersion()
getFileSystemDrives()
getNumberOfAvailableUpdates()
if apt_available:
getNumberOfAvailableUpdates()

# -----------------------------------------------------------------------------
# timer and timer funcs for ALIVE MQTT Notices handling
Expand Down Expand Up @@ -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)
)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 098c9f0

Please sign in to comment.