1 """Sensor for the zamg integration."""
3 from __future__
import annotations
5 from collections.abc
import Mapping
6 from dataclasses
import dataclass
11 SensorEntityDescription,
18 UnitOfPrecipitationDepth,
38 from .coordinator
import ZamgDataUpdateCoordinator
41 @dataclass(frozen=True, kw_only=True)
43 """Describes Zamg sensor entity."""
48 SENSOR_TYPES: tuple[ZamgSensorEntityDescription, ...] = (
52 native_unit_of_measurement=UnitOfPressure.HPA,
53 device_class=SensorDeviceClass.PRESSURE,
54 state_class=SensorStateClass.MEASUREMENT,
58 key=
"pressure_sealevel",
59 name=
"Pressure at Sea Level",
60 native_unit_of_measurement=UnitOfPressure.HPA,
61 device_class=SensorDeviceClass.PRESSURE,
62 state_class=SensorStateClass.MEASUREMENT,
68 native_unit_of_measurement=PERCENTAGE,
69 device_class=SensorDeviceClass.HUMIDITY,
70 state_class=SensorStateClass.MEASUREMENT,
76 native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
77 device_class=SensorDeviceClass.WIND_SPEED,
78 state_class=SensorStateClass.MEASUREMENT,
84 native_unit_of_measurement=DEGREE,
85 state_class=SensorStateClass.MEASUREMENT,
90 name=
"Top Wind Speed",
91 native_unit_of_measurement=UnitOfSpeed.METERS_PER_SECOND,
92 device_class=SensorDeviceClass.WIND_SPEED,
93 state_class=SensorStateClass.MEASUREMENT,
97 key=
"wind_max_bearing",
98 name=
"Top Wind Bearing",
99 native_unit_of_measurement=DEGREE,
100 state_class=SensorStateClass.MEASUREMENT,
104 key=
"sun_last_10min",
105 name=
"Sun Last 10 Minutes",
106 native_unit_of_measurement=UnitOfTime.SECONDS,
107 state_class=SensorStateClass.MEASUREMENT,
113 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
114 device_class=SensorDeviceClass.TEMPERATURE,
115 state_class=SensorStateClass.MEASUREMENT,
119 key=
"temperature_average",
120 name=
"Temperature Average",
121 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
122 device_class=SensorDeviceClass.TEMPERATURE,
123 state_class=SensorStateClass.MEASUREMENT,
128 name=
"Precipitation",
129 native_unit_of_measurement=UnitOfPrecipitationDepth.MILLIMETERS,
130 device_class=SensorDeviceClass.PRECIPITATION,
131 state_class=SensorStateClass.MEASUREMENT,
137 native_unit_of_measurement=UnitOfPrecipitationDepth.CENTIMETERS,
138 device_class=SensorDeviceClass.PRECIPITATION,
139 state_class=SensorStateClass.MEASUREMENT,
145 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
146 device_class=SensorDeviceClass.TEMPERATURE,
147 state_class=SensorStateClass.MEASUREMENT,
151 key=
"dewpoint_average",
152 name=
"Dew Point Average",
153 native_unit_of_measurement=UnitOfTemperature.CELSIUS,
154 device_class=SensorDeviceClass.TEMPERATURE,
155 state_class=SensorStateClass.MEASUREMENT,
160 SENSOR_KEYS: list[str] = [desc.key
for desc
in SENSOR_TYPES]
162 API_FIELDS: list[str] = [desc.para_name
for desc
in SENSOR_TYPES]
166 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
168 """Set up the ZAMG sensor platform."""
169 coordinator = hass.data[DOMAIN][entry.entry_id]
172 ZamgSensor(coordinator, entry.title, entry.data[CONF_STATION_ID], description)
173 for description
in SENSOR_TYPES
178 """Implementation of a ZAMG sensor."""
180 _attr_attribution = ATTRIBUTION
181 entity_description: ZamgSensorEntityDescription
185 coordinator: ZamgDataUpdateCoordinator,
188 description: ZamgSensorEntityDescription,
190 """Initialize the sensor."""
197 entry_type=DeviceEntryType.SERVICE,
198 identifiers={(DOMAIN, station_id)},
199 manufacturer=ATTRIBUTION,
200 configuration_url=MANUFACTURER_URL,
203 coordinator.api_fields = API_FIELDS
207 """Return the state of the sensor."""
209 return self.coordinator.data[self.
station_idstation_id][
217 """Return the state attributes."""
218 if (update_time := self.coordinator.data[
"last_update"])
is not None:
219 update_time = update_time.isoformat()
221 ATTR_STATION: self.coordinator.data[
"Name"],
222 ATTR_UPDATED: update_time,
StateType native_value(self)
None __init__(self, ZamgDataUpdateCoordinator coordinator, str name, str station_id, ZamgSensorEntityDescription description)
Mapping[str, str] extra_state_attributes(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)