Update Ambient Weather to include Lightning Strike Time and Distance (#114255)
* Update sensor.py to include Lightning Distance * Update strings.json to include Lightning Strikes distance * Update homeassistant/components/ambient_station/sensor.py * Update homeassistant/components/ambient_station/strings.json * Update device class lightning distance * Also add Last Lightning strike datetime --------- Co-authored-by: Aaron Bach <bachya1208@gmail.com> Co-authored-by: J. Nick Koston <nick@koston.org>pull/115059/head
parent
78bb21138c
commit
ed451cab3b
|
@ -2,7 +2,7 @@
|
|||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from homeassistant.components.sensor import (
|
||||
SensorDeviceClass,
|
||||
|
@ -19,6 +19,7 @@ from homeassistant.const import (
|
|||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
UnitOfIrradiance,
|
||||
UnitOfLength,
|
||||
UnitOfPrecipitationDepth,
|
||||
UnitOfPressure,
|
||||
UnitOfSpeed,
|
||||
|
@ -61,6 +62,8 @@ TYPE_HUMIDITYIN = "humidityin"
|
|||
TYPE_LASTRAIN = "lastRain"
|
||||
TYPE_LIGHTNING_PER_DAY = "lightning_day"
|
||||
TYPE_LIGHTNING_PER_HOUR = "lightning_hour"
|
||||
TYPE_LASTLIGHTNING_DISTANCE = "lightning_distance"
|
||||
TYPE_LASTLIGHTNING = "lightning_time"
|
||||
TYPE_MAXDAILYGUST = "maxdailygust"
|
||||
TYPE_MONTHLYRAININ = "monthlyrainin"
|
||||
TYPE_PM25 = "pm25"
|
||||
|
@ -296,6 +299,18 @@ SENSOR_DESCRIPTIONS = (
|
|||
native_unit_of_measurement="strikes",
|
||||
state_class=SensorStateClass.TOTAL,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key=TYPE_LASTLIGHTNING,
|
||||
translation_key="last_lightning_strike",
|
||||
device_class=SensorDeviceClass.TIMESTAMP,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key=TYPE_LASTLIGHTNING_DISTANCE,
|
||||
translation_key="last_lightning_strike_distance",
|
||||
native_unit_of_measurement=UnitOfLength.MILES,
|
||||
device_class=SensorDeviceClass.DISTANCE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
),
|
||||
SensorEntityDescription(
|
||||
key=TYPE_MAXDAILYGUST,
|
||||
translation_key="max_gust",
|
||||
|
@ -685,5 +700,9 @@ class AmbientWeatherSensor(AmbientWeatherEntity, SensorEntity):
|
|||
raw = self._ambient.stations[self._mac_address][ATTR_LAST_DATA][key]
|
||||
if key == TYPE_LASTRAIN:
|
||||
self._attr_native_value = datetime.strptime(raw, "%Y-%m-%dT%H:%M:%S.%f%z")
|
||||
elif key == TYPE_LASTLIGHTNING:
|
||||
self._attr_native_value = datetime.fromtimestamp(
|
||||
raw / 1000, tz=UTC
|
||||
) # Ambient uses millisecond epoch
|
||||
else:
|
||||
self._attr_native_value = raw
|
||||
|
|
|
@ -219,6 +219,12 @@
|
|||
"last_rain": {
|
||||
"name": "Last rain"
|
||||
},
|
||||
"last_lightning_strike": {
|
||||
"name": "Last Lightning strike"
|
||||
},
|
||||
"last_lightning_strike_distance": {
|
||||
"name": "Last Lightning strike distance"
|
||||
},
|
||||
"lightning_strikes_per_day": {
|
||||
"name": "Lightning strikes per day"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue