1 """Sensor for the zamg integration."""
3 from __future__
import annotations
8 UnitOfPrecipitationDepth,
18 from .const
import ATTRIBUTION, CONF_STATION_ID, DOMAIN, MANUFACTURER_URL
19 from .coordinator
import ZamgDataUpdateCoordinator
23 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
25 """Set up the ZAMG weather platform."""
26 coordinator = hass.data[DOMAIN][entry.entry_id]
28 [
ZamgWeather(coordinator, entry.title, entry.data[CONF_STATION_ID])]
33 """Representation of a weather condition."""
35 _attr_attribution = ATTRIBUTION
36 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
37 _attr_native_pressure_unit = UnitOfPressure.HPA
38 _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
39 _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
42 self, coordinator: ZamgDataUpdateCoordinator, name: str, station_id: str
44 """Initialise the platform with a data instance and station name."""
50 entry_type=DeviceEntryType.SERVICE,
51 identifiers={(DOMAIN, station_id)},
52 manufacturer=ATTRIBUTION,
53 configuration_url=MANUFACTURER_URL,
59 """Return the platform temperature."""
62 value := self.coordinator.data[self.
station_idstation_id][
"TLAM"][
"data"]
66 value := self.coordinator.data[self.
station_idstation_id][
"TL"][
"data"]
69 except (KeyError, ValueError, TypeError):
75 """Return the pressure."""
77 return float(self.coordinator.data[self.
station_idstation_id][
"P"][
"data"])
78 except (KeyError, ValueError, TypeError):
83 """Return the humidity."""
85 return float(self.coordinator.data[self.
station_idstation_id][
"RFAM"][
"data"])
86 except (KeyError, ValueError, TypeError):
91 """Return the wind speed."""
94 value := self.coordinator.data[self.
station_idstation_id][
"FFAM"][
"data"]
98 value := self.coordinator.data[self.
station_idstation_id][
"FFX"][
"data"]
101 except (KeyError, ValueError, TypeError):
107 """Return the wind bearing."""
110 value := self.coordinator.data[self.
station_idstation_id][
"DD"][
"data"]
114 value := self.coordinator.data[self.
station_idstation_id][
"DDX"][
"data"]
117 except (KeyError, ValueError, TypeError):
float|None wind_bearing(self)
float|None native_pressure(self)
float|None humidity(self)
None __init__(self, ZamgDataUpdateCoordinator coordinator, str name, str station_id)
float|None native_wind_speed(self)
float|None native_temperature(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)