Use native datetime value in Synology DSM sensors (#60176)

This commit is contained in:
Michael 2021-11-23 20:03:22 +01:00 committed by GitHub
parent c27948a82a
commit 9a328eae67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 6 deletions

View file

@ -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,

View file

@ -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