add last boot sensor

main
Hendrik Sokolowski 2024-04-12 23:35:14 +02:00
parent e194bd8c91
commit 0bb857a6b3
Signed by: hensoko
GPG Key ID: 5C36A01B80BCCC59
2 changed files with 22 additions and 0 deletions

View File

@ -67,6 +67,7 @@ async def main():
'battery': sensor.BatterySensor(device),
'display_brightness': sensor.DisplayBrightnessSensor(device, dbm),
'ip_address': sensor.IPAddressSensor(device),
'last_boot': sensor.LastBootSensor(device),
'temperature': sensor.TemperatureSensor(device)
};

View File

@ -4,6 +4,7 @@ import socket
import subprocess
import time
from datetime import datetime
from enum import Enum
import ha_mqtt_discoverable
@ -160,6 +161,25 @@ class IPAddressSensor():
self.value = IP
class LastBootSensor():
value = -1
mqtt_sensor = None
def __init__(self, device: Device):
boot_time_info = ha_mqtt_discoverable.sensors.SensorInfo(
name="Last boot",
device=device.get_mqtt_device(),
unique_id=f'{device.get_device_id()}_last_boot',
device_class='timestamp')
boot_time_settings = ha_mqtt_discoverable.Settings(mqtt=device.get_mqtt_settings(), entity=boot_time_info, manual_availability=True)
self.mqtt_sensor = ha_mqtt_discoverable.sensors.Sensor(boot_time_settings)
self.mqtt_sensor.set_availability(True)
self.mqtt_sensor.set_state(datetime.fromtimestamp(psutil.boot_time()).astimezone().isoformat())
def update_value(self):
pass
class TemperatureSensor():
value = -1
mqtt_sensor = None
@ -186,3 +206,4 @@ class TemperatureSensor():
self.mqtt_sensor.set_state(newValue)
self.value = newValue