add last boot sensor
parent
e194bd8c91
commit
0bb857a6b3
|
@ -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)
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue