Skip to content

Commit

Permalink
make available updates optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Senne Vande Sompele committed Jun 8, 2020
1 parent 8094424 commit 94e7138
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ It currently logs the following data:
| timezone | true | \ | Your local timezone (you can find the list of timezones here: [time zones](https://gist.github.com/heyalexej/8bf688fd67d7199be4a1682b3eec7568))
| power_integer_state | false | false | Return the power state in text or integer form
| update_interval | false | 60 | The update interval to send new values to the MQTT broker
| check_available_updates | false | false | Check the # of avaiblable updates
| check_wifi_strength | false | false | Check the wifi strength
| external_drives | false | \ | Declare external drives you want to check disk usage of (see example settings.yaml)

Expand Down
1 change: 1 addition & 0 deletions src/settings_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ timezone: Europe/Brussels
power_integer_state: false #defaults to false
update_interval: 60 #Defaults to 60
check_wifi_strength: true
check_available_updates: true
external_drives:
Drive1: /boot/
53 changes: 27 additions & 26 deletions src/system_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import paho.mqtt.client as mqtt
import pytz
import yaml
import apt
from pytz import timezone
import argparse

Expand Down Expand Up @@ -82,10 +81,10 @@ def updateSensors():
+ get_rpi_power_status()
+ '", "last_boot": "'
+ get_last_boot()
+ '", "updates": '
+ get_updates()
+ ', "last_message": "'
+ time.ctime()+'"')
if "check_available_updates" in settings and settings["check_available_updates"]:
payload_str = payload_str + ', "updates": ' + get_updates()
if "check_wifi_strength" in settings and settings["check_wifi_strength"]:
payload_str = payload_str + ', "wifi_strength": ' + get_wifi_strength()
if "external_drives" in settings:
Expand Down Expand Up @@ -351,29 +350,6 @@ def _parser():
qos=1,
retain=True,
)

mqttClient.publish(
topic="homeassistant/sensor/"
+ deviceName
+ "/"
+ deviceName
+ "Updates/config",
payload='{"name":"'
+ deviceName
+ 'Updates","state_topic":"system-sensors/sensor/'
+ deviceName
+ '/state","value_template":"{{ value_json.updates}}","unique_id":"'
+ deviceName.lower()
+ '_sensor_updates","device":{"identifiers":["'
+ deviceName.lower()
+ '_sensor"],"name":"'
+ deviceName
+ 'Sensors","model":"RPI '
+ deviceName
+ '","manufacturer":"RPI"}, "icon":"mdi:cellphone-arrow-down"}',
qos=1,
retain=True,
)

mqttClient.publish(
topic="homeassistant/sensor/"
Expand All @@ -398,6 +374,31 @@ def _parser():
retain=True,
)

if "check_available_updates" in settings and settings["check_available_updates"]:
import apt
mqttClient.publish(
topic="homeassistant/sensor/"
+ deviceName
+ "/"
+ deviceName
+ "Updates/config",
payload='{"name":"'
+ deviceName
+ 'Updates","state_topic":"system-sensors/sensor/'
+ deviceName
+ '/state","value_template":"{{ value_json.updates}}","unique_id":"'
+ deviceName.lower()
+ '_sensor_updates","device":{"identifiers":["'
+ deviceName.lower()
+ '_sensor"],"name":"'
+ deviceName
+ 'Sensors","model":"RPI '
+ deviceName
+ '","manufacturer":"RPI"}, "icon":"mdi:cellphone-arrow-down"}',
qos=1,
retain=True,
)

if "check_wifi_strength" in settings and settings["check_wifi_strength"]:
mqttClient.publish(
topic="homeassistant/sensor/"
Expand Down

0 comments on commit 94e7138

Please sign in to comment.