1 """Support for Ecowitt Weather Stations."""
3 from __future__
import annotations
6 from datetime
import datetime
7 from typing
import Final
9 from aioecowitt
import EcoWittSensor, EcoWittSensorTypes
14 SensorEntityDescription,
18 CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
19 CONCENTRATION_PARTS_PER_MILLION,
25 UnitOfElectricPotential,
28 UnitOfPrecipitationDepth,
39 from .
import EcowittConfigEntry
40 from .entity
import EcowittEntity
43 EcoWittSensorTypes.TEMPERATURE_C,
44 EcoWittSensorTypes.RAIN_COUNT_MM,
45 EcoWittSensorTypes.RAIN_RATE_MM,
46 EcoWittSensorTypes.LIGHTNING_DISTANCE_KM,
47 EcoWittSensorTypes.SPEED_KPH,
48 EcoWittSensorTypes.PRESSURE_HPA,
51 EcoWittSensorTypes.TEMPERATURE_F,
52 EcoWittSensorTypes.RAIN_COUNT_INCHES,
53 EcoWittSensorTypes.RAIN_RATE_INCHES,
54 EcoWittSensorTypes.LIGHTNING_DISTANCE_MILES,
55 EcoWittSensorTypes.SPEED_MPH,
56 EcoWittSensorTypes.PRESSURE_INHG,
60 ECOWITT_SENSORS_MAPPING: Final = {
63 device_class=SensorDeviceClass.HUMIDITY,
64 native_unit_of_measurement=PERCENTAGE,
65 state_class=SensorStateClass.MEASUREMENT,
68 key=
"DEGREE", native_unit_of_measurement=DEGREE
71 key=
"WATT_METERS_SQUARED",
72 device_class=SensorDeviceClass.IRRADIANCE,
73 native_unit_of_measurement=UnitOfIrradiance.WATTS_PER_SQUARE_METER,
74 state_class=SensorStateClass.MEASUREMENT,
78 native_unit_of_measurement=UV_INDEX,
79 state_class=SensorStateClass.MEASUREMENT,
83 device_class=SensorDeviceClass.PM25,
84 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
85 state_class=SensorStateClass.MEASUREMENT,
89 device_class=SensorDeviceClass.PM10,
90 native_unit_of_measurement=CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
91 state_class=SensorStateClass.MEASUREMENT,
94 key=
"BATTERY_PERCENTAGE",
95 device_class=SensorDeviceClass.BATTERY,
96 native_unit_of_measurement=PERCENTAGE,
97 state_class=SensorStateClass.MEASUREMENT,
98 entity_category=EntityCategory.DIAGNOSTIC,
101 key=
"BATTERY_VOLTAGE",
102 device_class=SensorDeviceClass.VOLTAGE,
103 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
104 state_class=SensorStateClass.MEASUREMENT,
105 entity_category=EntityCategory.DIAGNOSTIC,
109 device_class=SensorDeviceClass.CO2,
110 native_unit_of_measurement=CONCENTRATION_PARTS_PER_MILLION,
111 state_class=SensorStateClass.MEASUREMENT,
115 device_class=SensorDeviceClass.ILLUMINANCE,
116 native_unit_of_measurement=LIGHT_LUX,
117 state_class=SensorStateClass.MEASUREMENT,
120 key=
"TIMESTAMP", device_class=SensorDeviceClass.TIMESTAMP
124 device_class=SensorDeviceClass.VOLTAGE,
125 native_unit_of_measurement=UnitOfElectricPotential.VOLT,
126 state_class=SensorStateClass.MEASUREMENT,
127 entity_category=EntityCategory.DIAGNOSTIC,
130 key=
"LIGHTNING_COUNT",
131 native_unit_of_measurement=
"strikes",
132 state_class=SensorStateClass.TOTAL_INCREASING,
136 device_class=SensorDeviceClass.TEMPERATURE,
137 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
138 state_class=SensorStateClass.MEASUREMENT,
142 device_class=SensorDeviceClass.TEMPERATURE,
143 native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
144 state_class=SensorStateClass.MEASUREMENT,
148 native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
149 device_class=SensorDeviceClass.PRECIPITATION,
150 state_class=SensorStateClass.TOTAL_INCREASING,
153 key=
"RAIN_COUNT_INCHES",
154 native_unit_of_measurement=UnitOfPrecipitationDepth.INCHES,
155 device_class=SensorDeviceClass.PRECIPITATION,
156 state_class=SensorStateClass.TOTAL_INCREASING,
160 native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR,
161 state_class=SensorStateClass.MEASUREMENT,
162 device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
165 key=
"RAIN_RATE_INCHES",
166 native_unit_of_measurement=UnitOfVolumetricFlux.INCHES_PER_HOUR,
167 state_class=SensorStateClass.MEASUREMENT,
168 device_class=SensorDeviceClass.PRECIPITATION_INTENSITY,
171 key=
"LIGHTNING_DISTANCE_KM",
172 native_unit_of_measurement=UnitOfLength.KILOMETERS,
173 state_class=SensorStateClass.MEASUREMENT,
176 key=
"LIGHTNING_DISTANCE_MILES",
177 native_unit_of_measurement=UnitOfLength.MILES,
178 state_class=SensorStateClass.MEASUREMENT,
182 entity_registry_enabled_default=
False,
183 state_class=SensorStateClass.MEASUREMENT,
184 entity_category=EntityCategory.DIAGNOSTIC,
188 device_class=SensorDeviceClass.WIND_SPEED,
189 native_unit_of_measurement=UnitOfSpeed.KILOMETERS_PER_HOUR,
190 state_class=SensorStateClass.MEASUREMENT,
194 device_class=SensorDeviceClass.WIND_SPEED,
195 native_unit_of_measurement=UnitOfSpeed.MILES_PER_HOUR,
196 state_class=SensorStateClass.MEASUREMENT,
200 device_class=SensorDeviceClass.PRESSURE,
201 native_unit_of_measurement=UnitOfPressure.HPA,
202 state_class=SensorStateClass.MEASUREMENT,
206 device_class=SensorDeviceClass.PRESSURE,
207 native_unit_of_measurement=UnitOfPressure.INHG,
208 state_class=SensorStateClass.MEASUREMENT,
212 native_unit_of_measurement=PERCENTAGE,
213 state_class=SensorStateClass.MEASUREMENT,
220 entry: EcowittConfigEntry,
221 async_add_entities: AddEntitiesCallback,
223 """Add sensors if new."""
224 ecowitt = entry.runtime_data
227 """Add new sensor."""
228 if sensor.stype
not in ECOWITT_SENSORS_MAPPING:
232 if sensor.stype
in _METRIC
and hass.config.units
is not METRIC_SYSTEM:
234 if sensor.stype
in _IMPERIAL
and hass.config.units
is not US_CUSTOMARY_SYSTEM:
236 mapping = ECOWITT_SENSORS_MAPPING[sensor.stype]
239 description = dataclasses.replace(
252 description = dataclasses.replace(
254 state_class=SensorStateClass.MEASUREMENT,
259 ecowitt.new_sensor_cb.append(_new_sensor)
260 entry.async_on_unload(
lambda: ecowitt.new_sensor_cb.remove(_new_sensor))
263 for sensor
in ecowitt.sensors.values():
268 """Representation of a Ecowitt Sensor."""
271 self, sensor: EcoWittSensor, description: SensorEntityDescription
273 """Initialize the sensor."""
279 """Return the state of the sensor."""
280 return self.ecowitt.value
None __init__(self, EcoWittSensor sensor, SensorEntityDescription description)
StateType|datetime native_value(self)
None async_setup_entry(HomeAssistant hass, EcowittConfigEntry entry, AddEntitiesCallback async_add_entities)
None _new_sensor(EcoWittSensor sensor)