Migrate appropriate Ambient PWS sensors to use datetime state objects (#59942)

pull/58632/head
Aaron Bach 2021-11-19 18:06:39 -07:00 committed by GitHub
parent 40570b572d
commit 394ccae8a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,8 @@
"""Support for Ambient Weather Station sensors."""
from __future__ import annotations
from datetime import datetime
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
@ -643,6 +645,11 @@ class AmbientWeatherSensor(AmbientWeatherEntity, SensorEntity):
@callback
def update_from_latest_data(self) -> None:
"""Fetch new state data for the sensor."""
self._attr_native_value = self._ambient.stations[self._mac_address][
ATTR_LAST_DATA
][self.entity_description.key]
raw = self._ambient.stations[self._mac_address][ATTR_LAST_DATA][
self.entity_description.key
]
if self.entity_description.key == TYPE_LASTRAIN:
self._attr_native_value = datetime.strptime(raw, "%Y-%m-%dT%H:%M:%S.%f%z")
else:
self._attr_native_value = raw