Fix Xiaomi Miio providing strings as timestamps (#60979)

pull/60989/head
Franck Nijhof 2021-12-04 12:33:34 +01:00 committed by GitHub
parent c9bb688a79
commit ed6352a22b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -49,6 +49,7 @@ from homeassistant.const import (
VOLUME_CUBIC_METERS,
)
from homeassistant.core import callback
from homeassistant.util import dt as dt_util
from . import VacuumCoordinatorDataAttributes
from .const import (
@ -689,14 +690,24 @@ class XiaomiGenericSensor(XiaomiCoordinatedMiioEntity, SensorEntity):
def _determine_native_value(self):
"""Determine native value."""
if self.entity_description.parent_key is not None:
return self._extract_value_from_attribute(
native_value = self._extract_value_from_attribute(
getattr(self.coordinator.data, self.entity_description.parent_key),
self.entity_description.key,
)
else:
native_value = self._extract_value_from_attribute(
self.coordinator.data, self.entity_description.key
)
return self._extract_value_from_attribute(
self.coordinator.data, self.entity_description.key
)
if (
self.device_class == DEVICE_CLASS_TIMESTAMP
and native_value is not None
and (native_datetime := dt_util.parse_datetime(str(native_value)))
is not None
):
return native_datetime.astimezone(dt_util.UTC)
return native_value
class XiaomiAirQualityMonitor(XiaomiMiioEntity, SensorEntity):