Use native datetime value in NAM uptime sensor (#60241)

pull/58679/head^2
Maciej Bieniek 2021-11-23 23:25:48 +01:00 committed by GitHub
parent 9fa6daf47a
commit ac3dc0b090
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 8 deletions

View File

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