Use native datetime value in Synology DSM sensors (#60176)
This commit is contained in:
parent
c27948a82a
commit
9a328eae67
2 changed files with 5 additions and 6 deletions
|
@ -353,7 +353,7 @@ INFORMATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
|
|||
SynologyDSMSensorEntityDescription(
|
||||
api_key=SynoDSMInformation.API_KEY,
|
||||
key="temperature",
|
||||
name="temperature",
|
||||
name="Temperature",
|
||||
native_unit_of_measurement=TEMP_CELSIUS,
|
||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
|
@ -362,7 +362,7 @@ INFORMATION_SENSORS: tuple[SynologyDSMSensorEntityDescription, ...] = (
|
|||
SynologyDSMSensorEntityDescription(
|
||||
api_key=SynoDSMInformation.API_KEY,
|
||||
key="uptime",
|
||||
name="last boot",
|
||||
name="Last boot",
|
||||
device_class=DEVICE_CLASS_TIMESTAMP,
|
||||
entity_registry_enabled_default=False,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""Support for Synology DSM sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
from typing import Any
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity
|
||||
|
@ -164,7 +164,7 @@ class SynoDSMInfoSensor(SynoDSMSensor):
|
|||
"""Initialize the Synology SynoDSMInfoSensor entity."""
|
||||
super().__init__(api, coordinator, description)
|
||||
self._previous_uptime: str | None = None
|
||||
self._last_boot: str | None = None
|
||||
self._last_boot: datetime | None = None
|
||||
|
||||
@property
|
||||
def native_value(self) -> Any | None:
|
||||
|
@ -176,8 +176,7 @@ class SynoDSMInfoSensor(SynoDSMSensor):
|
|||
if self.entity_description.key == "uptime":
|
||||
# reboot happened or entity creation
|
||||
if self._previous_uptime is None or self._previous_uptime > attr:
|
||||
last_boot = utcnow() - timedelta(seconds=attr)
|
||||
self._last_boot = last_boot.replace(microsecond=0).isoformat()
|
||||
self._last_boot = utcnow() - timedelta(seconds=attr)
|
||||
|
||||
self._previous_uptime = attr
|
||||
return self._last_boot
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue