Merge pull request #54 from CFenner/noSleep

Remove sleep time
This commit is contained in:
Masoko
2024-02-01 20:21:02 +02:00
committed by GitHub
2 changed files with 3 additions and 32 deletions

View File

@@ -340,107 +340,81 @@ def publish_to_mqtt(cpu_load=0, cpu_temp=0, used_space=0, voltage=0, sys_clock_s
except Exception as e:
print("Error connecting to MQTT broker:", e)
return
client.loop_start()
# publish monitored values to MQTT
if config.cpu_load:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_cpuload/config",
config_json('cpuload'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/cpuload", cpu_load, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.cpu_temp:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_cputemp/config",
config_json('cputemp'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/cputemp", cpu_temp, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.used_space:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_diskusage/config",
config_json('diskusage'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/diskusage", used_space, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.voltage:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_voltage/config",
config_json('voltage'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/voltage", voltage, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.swap:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_swap/config",
config_json('swap'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/swap", swap, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.memory:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_memory/config",
config_json('memory'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/memory", memory, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.sys_clock_speed:
if config.discovery_messages:
client.publish(
"homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_sys_clock_speed/config",
config_json('sys_clock_speed'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/sys_clock_speed", sys_clock_speed, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.uptime:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_uptime_days/config",
config_json('uptime_days'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/uptime_days", uptime_days, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.uptime_seconds:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_uptime/config",
config_json('uptime'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/uptime_seconds", uptime_seconds, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.wifi_signal:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_wifi_signal/config",
config_json('wifi_signal'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/wifi_signal", wifi_signal, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.wifi_signal_dbm:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_wifi_signal_dbm/config",
config_json('wifi_signal_dbm'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/wifi_signal_dbm", wifi_signal_dbm, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.rpi5_fan_speed:
if config.discovery_messages:
client.publish("homeassistant/sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_rpi5_fan_speed/config",
config_json('rpi5_fan_speed'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/rpi5_fan_speed", rpi5_fan_speed, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
if config.git_update:
if config.discovery_messages:
client.publish("homeassistant/binary_sensor/" + config.mqtt_topic_prefix + "/" + hostname + "_git_update/config",
config_json('git_update'), qos=config.qos)
time.sleep(config.sleep_time)
client.publish(config.mqtt_topic_prefix + "/" + hostname + "/git_update", git_update, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
client.loop_stop()
if config.update:
if config.discovery_messages:
client.publish("homeassistant/update/" + hostname + "/config",
config_json('update'), qos=config.qos)
time.sleep(config.sleep_time)
# client.publish(config.mqtt_topic_prefix + "/" + hostname + "/git_update", git_update, qos=config.qos, retain=config.retain)
time.sleep(config.sleep_time)
# disconnect from mqtt server
client.disconnect()