Migrate appropriate Ambient PWS sensors to use datetime state objects (#59942)
parent
40570b572d
commit
394ccae8a1
|
@ -1,6 +1,8 @@
|
||||||
"""Support for Ambient Weather Station sensors."""
|
"""Support for Ambient Weather Station sensors."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
STATE_CLASS_MEASUREMENT,
|
STATE_CLASS_MEASUREMENT,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
STATE_CLASS_TOTAL_INCREASING,
|
||||||
|
@ -643,6 +645,11 @@ class AmbientWeatherSensor(AmbientWeatherEntity, SensorEntity):
|
||||||
@callback
|
@callback
|
||||||
def update_from_latest_data(self) -> None:
|
def update_from_latest_data(self) -> None:
|
||||||
"""Fetch new state data for the sensor."""
|
"""Fetch new state data for the sensor."""
|
||||||
self._attr_native_value = self._ambient.stations[self._mac_address][
|
raw = self._ambient.stations[self._mac_address][ATTR_LAST_DATA][
|
||||||
ATTR_LAST_DATA
|
self.entity_description.key
|
||||||
][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
|
||||||
|
|
Loading…
Reference in New Issue