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>
This commit is contained in:
parent
78bb21138c
commit
ed451cab3b
2 changed files with 26 additions and 1 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
|
@ -19,6 +19,7 @@ from homeassistant.const import (
|
||||||
LIGHT_LUX,
|
LIGHT_LUX,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
UnitOfIrradiance,
|
UnitOfIrradiance,
|
||||||
|
UnitOfLength,
|
||||||
UnitOfPrecipitationDepth,
|
UnitOfPrecipitationDepth,
|
||||||
UnitOfPressure,
|
UnitOfPressure,
|
||||||
UnitOfSpeed,
|
UnitOfSpeed,
|
||||||
|
@ -61,6 +62,8 @@ TYPE_HUMIDITYIN = "humidityin"
|
||||||
TYPE_LASTRAIN = "lastRain"
|
TYPE_LASTRAIN = "lastRain"
|
||||||
TYPE_LIGHTNING_PER_DAY = "lightning_day"
|
TYPE_LIGHTNING_PER_DAY = "lightning_day"
|
||||||
TYPE_LIGHTNING_PER_HOUR = "lightning_hour"
|
TYPE_LIGHTNING_PER_HOUR = "lightning_hour"
|
||||||
|
TYPE_LASTLIGHTNING_DISTANCE = "lightning_distance"
|
||||||
|
TYPE_LASTLIGHTNING = "lightning_time"
|
||||||
TYPE_MAXDAILYGUST = "maxdailygust"
|
TYPE_MAXDAILYGUST = "maxdailygust"
|
||||||
TYPE_MONTHLYRAININ = "monthlyrainin"
|
TYPE_MONTHLYRAININ = "monthlyrainin"
|
||||||
TYPE_PM25 = "pm25"
|
TYPE_PM25 = "pm25"
|
||||||
|
@ -296,6 +299,18 @@ SENSOR_DESCRIPTIONS = (
|
||||||
native_unit_of_measurement="strikes",
|
native_unit_of_measurement="strikes",
|
||||||
state_class=SensorStateClass.TOTAL,
|
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(
|
SensorEntityDescription(
|
||||||
key=TYPE_MAXDAILYGUST,
|
key=TYPE_MAXDAILYGUST,
|
||||||
translation_key="max_gust",
|
translation_key="max_gust",
|
||||||
|
@ -685,5 +700,9 @@ class AmbientWeatherSensor(AmbientWeatherEntity, SensorEntity):
|
||||||
raw = self._ambient.stations[self._mac_address][ATTR_LAST_DATA][key]
|
raw = self._ambient.stations[self._mac_address][ATTR_LAST_DATA][key]
|
||||||
if key == TYPE_LASTRAIN:
|
if key == TYPE_LASTRAIN:
|
||||||
self._attr_native_value = datetime.strptime(raw, "%Y-%m-%dT%H:%M:%S.%f%z")
|
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:
|
else:
|
||||||
self._attr_native_value = raw
|
self._attr_native_value = raw
|
||||||
|
|
|
@ -219,6 +219,12 @@
|
||||||
"last_rain": {
|
"last_rain": {
|
||||||
"name": "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": {
|
"lightning_strikes_per_day": {
|
||||||
"name": "Lightning strikes per day"
|
"name": "Lightning strikes per day"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue