UniFi has changed to not report uptime in epoch form (#47492)

This commit is contained in:
Robert Svensson 2021-03-12 20:55:11 +01:00 committed by GitHub
parent 9a98dcf432
commit 597bf67f5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 199 additions and 148 deletions

View file

@ -3,6 +3,9 @@
Support for bandwidth sensors of network clients.
Support for uptime sensors of network clients.
"""
from datetime import datetime, timedelta
from homeassistant.components.sensor import DEVICE_CLASS_TIMESTAMP, DOMAIN
from homeassistant.const import DATA_MEGABYTES
from homeassistant.core import callback
@ -140,8 +143,10 @@ class UniFiUpTimeSensor(UniFiClient):
return f"{super().name} {self.TYPE.capitalize()}"
@property
def state(self) -> int:
def state(self) -> datetime:
"""Return the uptime of the client."""
if self.client.uptime < 1000000000:
return (dt_util.now() - timedelta(seconds=self.client.uptime)).isoformat()
return dt_util.utc_from_timestamp(float(self.client.uptime)).isoformat()
async def options_updated(self) -> None: