1 """Support for the OpenWeatherMap (OWM) service."""
3 from __future__
import annotations
7 SingleCoordinatorWeatherEntity,
12 UnitOfPrecipitationDepth,
21 from .
import OpenweathermapConfigEntry
26 ATTR_API_DAILY_FORECAST,
28 ATTR_API_FEELS_LIKE_TEMPERATURE,
29 ATTR_API_HOURLY_FORECAST,
33 ATTR_API_VISIBILITY_DISTANCE,
34 ATTR_API_WIND_BEARING,
41 OWM_MODE_FREE_FORECAST,
45 from .coordinator
import WeatherUpdateCoordinator
50 config_entry: OpenweathermapConfigEntry,
51 async_add_entities: AddEntitiesCallback,
53 """Set up OpenWeatherMap weather entity based on a config entry."""
54 domain_data = config_entry.runtime_data
55 name = domain_data.name
56 mode = domain_data.mode
57 weather_coordinator = domain_data.coordinator
59 unique_id = f
"{config_entry.unique_id}"
66 """Implementation of an OpenWeatherMap sensor."""
68 _attr_attribution = ATTRIBUTION
69 _attr_should_poll =
False
71 _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
72 _attr_native_pressure_unit = UnitOfPressure.HPA
73 _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
74 _attr_native_wind_speed_unit = UnitOfSpeed.METERS_PER_SECOND
75 _attr_native_visibility_unit = UnitOfLength.METERS
82 weather_coordinator: WeatherUpdateCoordinator,
84 """Initialize the sensor."""
85 super().
__init__(weather_coordinator)
89 entry_type=DeviceEntryType.SERVICE,
90 identifiers={(DOMAIN, unique_id)},
91 manufacturer=MANUFACTURER,
95 if mode
in (OWM_MODE_V30, OWM_MODE_V25):
97 WeatherEntityFeature.FORECAST_DAILY
98 | WeatherEntityFeature.FORECAST_HOURLY
100 elif mode == OWM_MODE_FREE_FORECAST:
105 """Return the current condition."""
106 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_CONDITION)
110 """Return the Cloud coverage in %."""
111 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_CLOUDS)
115 """Return the apparent temperature."""
116 return self.coordinator.data[ATTR_API_CURRENT].
get(
117 ATTR_API_FEELS_LIKE_TEMPERATURE
122 """Return the temperature."""
123 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_TEMPERATURE)
127 """Return the pressure."""
128 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_PRESSURE)
132 """Return the humidity."""
133 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_HUMIDITY)
137 """Return the dew point."""
138 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_DEW_POINT)
142 """Return the wind gust speed."""
143 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_WIND_GUST)
147 """Return the wind speed."""
148 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_WIND_SPEED)
152 """Return the wind bearing."""
153 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_WIND_BEARING)
157 """Return visibility."""
158 return self.coordinator.data[ATTR_API_CURRENT].
get(ATTR_API_VISIBILITY_DISTANCE)
162 """Return the daily forecast in native units."""
163 return self.coordinator.data[ATTR_API_DAILY_FORECAST]
167 """Return the hourly forecast in native units."""
168 return self.coordinator.data[ATTR_API_HOURLY_FORECAST]
list[Forecast]|None _async_forecast_hourly(self)
float|None native_temperature(self)
float|None native_wind_gust_speed(self)
None __init__(self, str name, str unique_id, str mode, WeatherUpdateCoordinator weather_coordinator)
float|None native_dew_point(self)
float|None native_apparent_temperature(self)
float|str|None visibility(self)
float|None humidity(self)
list[Forecast]|None _async_forecast_daily(self)
float|None native_pressure(self)
float|None native_wind_speed(self)
float|str|None wind_bearing(self)
float|None cloud_coverage(self)
web.Response get(self, web.Request request, str config_key)
None async_setup_entry(HomeAssistant hass, OpenweathermapConfigEntry config_entry, AddEntitiesCallback async_add_entities)