Skip to content

Commit 94e7138

Browse files
author
Senne Vande Sompele
committed
make available updates optional
1 parent 8094424 commit 94e7138

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ It currently logs the following data:
3131
| timezone | true | \ | Your local timezone (you can find the list of timezones here: [time zones](https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568))
3232
| power_integer_state | false | false | Return the power state in text or integer form
3333
| update_interval | false | 60 | The update interval to send new values to the MQTT broker
34+
| check_available_updates | false | false | Check the # of avaiblable updates
3435
| check_wifi_strength | false | false | Check the wifi strength
3536
| external_drives | false | \ | Declare external drives you want to check disk usage of (see example settings.yaml)
3637

src/settings_example.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ timezone: Europe/Brussels
99
power_integer_state: false #defaults to false
1010
update_interval: 60 #Defaults to 60
1111
check_wifi_strength: true
12+
check_available_updates: true
1213
external_drives:
1314
Drive1: /boot/

src/system_sensors.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import paho.mqtt.client as mqtt
1111
import pytz
1212
import yaml
13-
import apt
1413
from pytz import timezone
1514
import argparse
1615

@@ -82,10 +81,10 @@ def updateSensors():
8281
+ get_rpi_power_status()
8382
+ '", "last_boot": "'
8483
+ get_last_boot()
85-
+ '", "updates": '
86-
+ get_updates()
8784
+ ', "last_message": "'
8885
+ time.ctime()+'"')
86+
if "check_available_updates" in settings and settings["check_available_updates"]:
87+
payload_str = payload_str + ', "updates": ' + get_updates()
8988
if "check_wifi_strength" in settings and settings["check_wifi_strength"]:
9089
payload_str = payload_str + ', "wifi_strength": ' + get_wifi_strength()
9190
if "external_drives" in settings:
@@ -351,29 +350,6 @@ def _parser():
351350
qos=1,
352351
retain=True,
353352
)
354-
355-
mqttClient.publish(
356-
topic="homeassistant/sensor/"
357-
+ deviceName
358-
+ "/"
359-
+ deviceName
360-
+ "Updates/config",
361-
payload='{"name":"'
362-
+ deviceName
363-
+ 'Updates","state_topic":"system-sensors/sensor/'
364-
+ deviceName
365-
+ '/state","value_template":"{{ value_json.updates}}","unique_id":"'
366-
+ deviceName.lower()
367-
+ '_sensor_updates","device":{"identifiers":["'
368-
+ deviceName.lower()
369-
+ '_sensor"],"name":"'
370-
+ deviceName
371-
+ 'Sensors","model":"RPI '
372-
+ deviceName
373-
+ '","manufacturer":"RPI"}, "icon":"mdi:cellphone-arrow-down"}',
374-
qos=1,
375-
retain=True,
376-
)
377353

378354
mqttClient.publish(
379355
topic="homeassistant/sensor/"
@@ -398,6 +374,31 @@ def _parser():
398374
retain=True,
399375
)
400376

377+
if "check_available_updates" in settings and settings["check_available_updates"]:
378+
import apt
379+
mqttClient.publish(
380+
topic="homeassistant/sensor/"
381+
+ deviceName
382+
+ "/"
383+
+ deviceName
384+
+ "Updates/config",
385+
payload='{"name":"'
386+
+ deviceName
387+
+ 'Updates","state_topic":"system-sensors/sensor/'
388+
+ deviceName
389+
+ '/state","value_template":"{{ value_json.updates}}","unique_id":"'
390+
+ deviceName.lower()
391+
+ '_sensor_updates","device":{"identifiers":["'
392+
+ deviceName.lower()
393+
+ '_sensor"],"name":"'
394+
+ deviceName
395+
+ 'Sensors","model":"RPI '
396+
+ deviceName
397+
+ '","manufacturer":"RPI"}, "icon":"mdi:cellphone-arrow-down"}',
398+
qos=1,
399+
retain=True,
400+
)
401+
401402
if "check_wifi_strength" in settings and settings["check_wifi_strength"]:
402403
mqttClient.publish(
403404
topic="homeassistant/sensor/"

0 commit comments

Comments
 (0)