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."""
from __future__ import annotations
from datetime import timedelta
from datetime import datetime, timedelta
import logging
from typing import cast
@ -75,7 +75,7 @@ class NAMSensor(CoordinatorEntity, SensorEntity):
self.entity_description = description
@property
def native_value(self) -> StateType:
def native_value(self) -> StateType | datetime:
"""Return the state."""
return cast(
StateType, getattr(self.coordinator.data, self.entity_description.key)
@ -99,11 +99,7 @@ class NAMSensorUptime(NAMSensor):
"""Define an Nettigo Air Monitor uptime sensor."""
@property
def native_value(self) -> str:
def native_value(self) -> datetime:
"""Return the state."""
uptime_sec = getattr(self.coordinator.data, self.entity_description.key)
return (
(utcnow() - timedelta(seconds=uptime_sec))
.replace(microsecond=0)
.isoformat()
)
return utcnow() - timedelta(seconds=uptime_sec)