Use native datetime value in NAM uptime sensor (#60241)
parent
9fa6daf47a
commit
ac3dc0b090
|
@ -1,7 +1,7 @@
|
||||||
"""Support for the Nettigo Air Monitor service."""
|
"""Support for the Nettigo Air Monitor service."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import timedelta
|
from datetime import datetime, timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ class NAMSensor(CoordinatorEntity, SensorEntity):
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType | datetime:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return cast(
|
return cast(
|
||||||
StateType, getattr(self.coordinator.data, self.entity_description.key)
|
StateType, getattr(self.coordinator.data, self.entity_description.key)
|
||||||
|
@ -99,11 +99,7 @@ class NAMSensorUptime(NAMSensor):
|
||||||
"""Define an Nettigo Air Monitor uptime sensor."""
|
"""Define an Nettigo Air Monitor uptime sensor."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> str:
|
def native_value(self) -> datetime:
|
||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
uptime_sec = getattr(self.coordinator.data, self.entity_description.key)
|
uptime_sec = getattr(self.coordinator.data, self.entity_description.key)
|
||||||
return (
|
return utcnow() - timedelta(seconds=uptime_sec)
|
||||||
(utcnow() - timedelta(seconds=uptime_sec))
|
|
||||||
.replace(microsecond=0)
|
|
||||||
.isoformat()
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in New Issue