1 """Support for Ambient Weather Network sensors."""
3 from __future__
import annotations
5 from datetime
import datetime
10 SensorEntityDescription,
14 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
15 CONCENTRATION_PARTS_PER_MILLION,
21 UnitOfPrecipitationDepth,
31 from .
import AmbientNetworkConfigEntry
32 from .coordinator
import AmbientNetworkDataUpdateCoordinator
33 from .entity
import AmbientNetworkEntity
35 TYPE_AQI_PM25 =
"aqi_pm25"
36 TYPE_AQI_PM25_24H =
"aqi_pm25_24h"
37 TYPE_BAROMABSIN =
"baromabsin"
38 TYPE_BAROMRELIN =
"baromrelin"
40 TYPE_DAILYRAININ =
"dailyrainin"
41 TYPE_DEWPOINT =
"dewPoint"
42 TYPE_EVENTRAININ =
"eventrainin"
43 TYPE_FEELSLIKE =
"feelsLike"
44 TYPE_HOURLYRAININ =
"hourlyrainin"
45 TYPE_HUMIDITY =
"humidity"
46 TYPE_LASTRAIN =
"lastRain"
47 TYPE_LIGHTNING_DISTANCE =
"lightning_distance"
48 TYPE_LIGHTNING_PER_DAY =
"lightning_day"
49 TYPE_LIGHTNING_PER_HOUR =
"lightning_hour"
50 TYPE_MAXDAILYGUST =
"maxdailygust"
51 TYPE_MONTHLYRAININ =
"monthlyrainin"
53 TYPE_PM25_24H =
"pm25_24h"
54 TYPE_SOLARRADIATION =
"solarradiation"
57 TYPE_WEEKLYRAININ =
"weeklyrainin"
58 TYPE_WINDDIR =
"winddir"
59 TYPE_WINDGUSTMPH =
"windgustmph"
60 TYPE_WINDSPEEDMPH =
"windspeedmph"
61 TYPE_YEARLYRAININ =
"yearlyrainin"
64 SENSOR_DESCRIPTIONS = (
67 translation_key=
"pm25_aqi",
68 device_class=SensorDeviceClass.AQI,
69 state_class=SensorStateClass.MEASUREMENT,
70 suggested_display_precision=0,
73 key=TYPE_AQI_PM25_24H,
74 translation_key=
"pm25_aqi_24h_average",
75 device_class=SensorDeviceClass.AQI,
76 state_class=SensorStateClass.MEASUREMENT,
77 suggested_display_precision=0,
78 entity_registry_enabled_default=
False,
82 translation_key=
"absolute_pressure",
83 native_unit_of_measurement=UnitOfPressure.INHG,
84 device_class=SensorDeviceClass.PRESSURE,
85 state_class=SensorStateClass.MEASUREMENT,
86 suggested_display_precision=2,
87 entity_registry_enabled_default=
False,
91 translation_key=
"relative_pressure",
92 native_unit_of_measurement=UnitOfPressure.INHG,
93 device_class=SensorDeviceClass.PRESSURE,
94 state_class=SensorStateClass.MEASUREMENT,
95 suggested_display_precision=2,
99 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
100 device_class=SensorDeviceClass.CO2,
101 state_class=SensorStateClass.MEASUREMENT,
102 suggested_display_precision=2,
103 entity_registry_enabled_default=
False,
106 key=TYPE_DAILYRAININ,
107 translation_key=
"daily_rain",
108 native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES,
109 device_class=SensorDeviceClass.PRECIPITATION,
110 state_class=SensorStateClass.TOTAL,
111 suggested_display_precision=2,
115 translation_key=
"dew_point",
116 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
117 device_class=SensorDeviceClass.TEMPERATURE,
118 state_class=SensorStateClass.MEASUREMENT,
119 suggested_display_precision=1,
123 translation_key=
"feels_like",
124 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
125 device_class=SensorDeviceClass.TEMPERATURE,
126 state_class=SensorStateClass.MEASUREMENT,
127 suggested_display_precision=1,
130 key=TYPE_HOURLYRAININ,
131 translation_key=
"hourly_rain",
132 native_unit_of_measurement=UnitOfVolumetricFlux.INCHES_PER_HOUR,
133 state_class=SensorStateClass.MEASUREMENT,
134 device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
135 suggested_display_precision=2,
139 native_unit_of_measurement=PERCENTAGE,
140 device_class=SensorDeviceClass.HUMIDITY,
141 state_class=SensorStateClass.MEASUREMENT,
142 suggested_display_precision=1,
146 translation_key=
"last_rain",
147 device_class=SensorDeviceClass.TIMESTAMP,
148 entity_registry_enabled_default=
False,
151 key=TYPE_LIGHTNING_PER_DAY,
152 translation_key=
"lightning_strikes_per_day",
153 native_unit_of_measurement=
"strikes",
154 state_class=SensorStateClass.TOTAL,
155 entity_registry_enabled_default=
False,
158 key=TYPE_LIGHTNING_PER_HOUR,
159 translation_key=
"lightning_strikes_per_hour",
160 native_unit_of_measurement=
"strikes/hour",
161 state_class=SensorStateClass.TOTAL,
162 entity_registry_enabled_default=
False,
165 key=TYPE_LIGHTNING_DISTANCE,
166 translation_key=
"lightning_distance",
167 native_unit_of_measurement=UnitOfLength.MILES,
168 device_class=SensorDeviceClass.DISTANCE,
169 state_class=SensorStateClass.MEASUREMENT,
170 suggested_display_precision=2,
171 entity_registry_enabled_default=
False,
174 key=TYPE_MAXDAILYGUST,
175 translation_key=
"max_daily_gust",
176 native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR,
177 device_class=SensorDeviceClass.WIND_SPEED,
178 state_class=SensorStateClass.MEASUREMENT,
179 suggested_display_precision=1,
182 key=TYPE_MONTHLYRAININ,
183 translation_key=
"monthly_rain",
184 native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES,
185 device_class=SensorDeviceClass.PRECIPITATION,
186 state_class=SensorStateClass.TOTAL,
187 suggested_display_precision=2,
188 entity_registry_enabled_default=
False,
192 translation_key=
"pm25_24h_average",
193 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
194 device_class=SensorDeviceClass.PM25,
195 suggested_display_precision=1,
196 entity_registry_enabled_default=
False,
200 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
201 device_class=SensorDeviceClass.PM25,
202 state_class=SensorStateClass.MEASUREMENT,
203 suggested_display_precision=1,
204 entity_registry_enabled_default=
False,
207 key=TYPE_SOLARRADIATION,
208 native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
209 device_class=SensorDeviceClass.IRRADIANCE,
210 state_class=SensorStateClass.MEASUREMENT,
211 suggested_display_precision=1,
212 entity_registry_enabled_default=
False,
216 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
217 device_class=SensorDeviceClass.TEMPERATURE,
218 state_class=SensorStateClass.MEASUREMENT,
219 suggested_display_precision=1,
223 translation_key=
"uv_index",
224 native_unit_of_measurement=
"index",
225 state_class=SensorStateClass.MEASUREMENT,
226 suggested_display_precision=1,
229 key=TYPE_WEEKLYRAININ,
230 translation_key=
"weekly_rain",
231 native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES,
232 device_class=SensorDeviceClass.PRECIPITATION,
233 state_class=SensorStateClass.TOTAL,
234 suggested_display_precision=2,
235 entity_registry_enabled_default=
False,
239 translation_key=
"wind_direction",
240 native_unit_of_measurement=DEGREE,
241 suggested_display_precision=0,
242 entity_registry_enabled_default=
False,
245 key=TYPE_WINDGUSTMPH,
246 translation_key=
"wind_gust",
247 native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR,
248 device_class=SensorDeviceClass.WIND_SPEED,
249 state_class=SensorStateClass.MEASUREMENT,
250 suggested_display_precision=1,
253 key=TYPE_WINDSPEEDMPH,
254 native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR,
255 device_class=SensorDeviceClass.WIND_SPEED,
256 state_class=SensorStateClass.MEASUREMENT,
257 suggested_display_precision=1,
260 key=TYPE_YEARLYRAININ,
261 translation_key=
"yearly_rain",
262 native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES,
263 device_class=SensorDeviceClass.PRECIPITATION,
264 state_class=SensorStateClass.TOTAL,
265 suggested_display_precision=2,
266 entity_registry_enabled_default=
False,
273 entry: AmbientNetworkConfigEntry,
274 async_add_entities: AddEntitiesCallback,
276 """Set up the Ambient Network sensor entities."""
278 coordinator = entry.runtime_data
279 if coordinator.config_entry
is not None:
284 coordinator.config_entry.data[CONF_MAC],
286 for description
in SENSOR_DESCRIPTIONS
287 if coordinator.data.get(description.key)
is not None
292 """A sensor implementation for an Ambient Weather Network sensor."""
296 coordinator: AmbientNetworkDataUpdateCoordinator,
297 description: SensorEntityDescription,
300 """Initialize a sensor object."""
301 super().
__init__(coordinator, description, mac_address)
304 """Update sensor attributes."""
309 value = datetime.fromtimestamp(
310 value / 1000, tz=dt_util.get_default_time_zone()
316 if self.coordinator.last_measured
is not None:
318 "last_measured": self.coordinator.last_measured
None __init__(self, AmbientNetworkDataUpdateCoordinator coordinator, SensorEntityDescription description, str mac_address)
_attr_extra_state_attributes
SensorDeviceClass|None device_class(self)
str|None device_class(self)
None async_setup_entry(HomeAssistant hass, AmbientNetworkConfigEntry entry, AddEntitiesCallback async_add_entities)