def send_update(self, force=False): undervoltage = new_under_voltage() if undervoltage is None: self.__logger.error( "Undervoltage auf diesem System nicht unterstützt!") elif undervoltage.get() == self._prev_deg and not force: self.__logger.debug("Not changed {} last {} return".format( undervoltage.get(), self._prev_deg)) return for call in self._callables: try: call(undervoltage) except: self.__logger.exception("Undervoltage callback error") self.__logger.debug("Publishing undervoltage {}.".format( undervoltage.get())) self._prev_deg = None if undervoltage is None else undervoltage.get()
mqttClient.username_pw_set( settings["mqtt"]["user"], settings["mqtt"]["password"] ) # Username and pass if configured otherwise you should comment out this signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) if "port" in settings["mqtt"]: mqttClient.connect(settings["mqtt"]["hostname"], settings["mqtt"]["port"]) else: mqttClient.connect(settings["mqtt"]["hostname"], 1883) try: remove_old_topics() send_config_message(mqttClient) except: write_message_to_console("something whent wrong") _underVoltage = new_under_voltage() job = Job(interval=timedelta(seconds=WAIT_TIME_SECONDS), execute=updateSensors) job.start() mqttClient.loop_start() while True: try: sys.stdout.flush() time.sleep(1) except ProgramKilled: write_message_to_console("Program killed: running cleanup code") mqttClient.publish( f"system-sensors/sensor/{deviceName}/availability", "offline",
import pytz import psutil import socket import platform import subprocess import datetime as dt import sys # Only needed if using alternate method of obtaining CPU temperature (see commented out code for approach) #from os import walk rpi_power_disabled = True try: from rpi_bad_power import new_under_voltage if new_under_voltage() is not None: # Only enable if import works and function returns a value rpi_power_disabled = False except ImportError: pass try: import apt apt_disabled = False except ImportError: apt_disabled = True # Get OS information OS_DATA = {} with open('/etc/os-release') as f: