@@ -151,30 +151,14 @@ def __init__(
151
151
"""Initialize."""
152
152
super ().__init__ (coordinator )
153
153
self ._hass : HomeAssistant = hass
154
- self ._unique_id : str = unique_id
154
+ self ._attr_unique_id = unique_id
155
155
self ._config : ConfigEntry = config
156
156
self ._forecast_mode : ForecastMode = forecast_mode
157
- self ._device : DeviceInfo = device
157
+ self ._attr_device_info = device
158
158
self ._conf_current_weather : str = self ._config .options .get (
159
159
CONF_CURRENT_WEATHER , CONF_CURRENT_WEATHER_DEFAULT
160
160
)
161
161
162
- self ._attr_supported_features = 0
163
- if self ._config .options .get (CONF_FORECAST , CONF_FORECAST_DEFAULT ):
164
- if self ._forecast_mode in (ForecastMode .STANDARD , ForecastMode .DAILY ):
165
- self ._attr_supported_features |= WeatherEntityFeature .FORECAST_DAILY
166
- if self ._forecast_mode in (ForecastMode .STANDARD , ForecastMode .HOURLY ):
167
- self ._attr_supported_features |= WeatherEntityFeature .FORECAST_HOURLY
168
-
169
- @property
170
- def unique_id (self ) -> str :
171
- """Return unique ID."""
172
- return self ._unique_id
173
-
174
- @property
175
- def name (self ) -> str :
176
- """Return the name of the sensor."""
177
-
178
162
name = self ._config .title
179
163
name_appendix = ""
180
164
@@ -189,23 +173,32 @@ def name(self) -> str:
189
173
if name is None :
190
174
name = "DWD"
191
175
192
- return f"{ name } { name_appendix } "
176
+ self ._attr_name = f"{ name } { name_appendix } "
177
+
178
+ self ._attr_entity_registry_enabled_default = (
179
+ self ._forecast_mode == ForecastMode .STANDARD
180
+ )
181
+
182
+ self ._attr_supported_features = 0
183
+ if self ._config .options .get (CONF_FORECAST , CONF_FORECAST_DEFAULT ):
184
+ if self ._forecast_mode in (ForecastMode .STANDARD , ForecastMode .DAILY ):
185
+ self ._attr_supported_features |= WeatherEntityFeature .FORECAST_DAILY
186
+ if self ._forecast_mode in (ForecastMode .STANDARD , ForecastMode .HOURLY ):
187
+ self ._attr_supported_features |= WeatherEntityFeature .FORECAST_HOURLY
188
+
189
+ self ._attr_native_temperature_unit = UnitOfTemperature .CELSIUS
190
+ self ._attr_native_pressure_unit = UnitOfPressure .HPA
191
+ self ._attr_native_visibility_unit = UnitOfLength .KILOMETERS
192
+ self ._attr_native_wind_speed_unit = UnitOfSpeed .KILOMETERS_PER_HOUR
193
+ self ._attr_native_precipitation_unit = UnitOfLength .MILLIMETERS
194
+
195
+ self ._attr_attribution = ATTRIBUTION
193
196
194
197
@property
195
198
def available (self ) -> bool :
196
199
"""Return True if entity is available."""
197
200
return self .coordinator .last_update_success
198
201
199
- @property
200
- def device_info (self ) -> DeviceInfo :
201
- """Device info."""
202
- return self ._device
203
-
204
- @property
205
- def entity_registry_enabled_default (self ) -> bool :
206
- """Return if the entity should be enabled when first added to the entity registry."""
207
- return self ._forecast_mode == ForecastMode .STANDARD
208
-
209
202
@property
210
203
def condition (self ) -> str | None :
211
204
"""Return the current condition."""
@@ -246,11 +239,6 @@ def native_temperature(self) -> float | None:
246
239
DWD_MEASUREMENT_TEMPERATURE , ATTR_FORECAST_NATIVE_TEMP
247
240
)
248
241
249
- @property
250
- def native_temperature_unit (self ) -> str :
251
- """Return the native unit of measurement for temperature."""
252
- return UnitOfTemperature .CELSIUS
253
-
254
242
@property
255
243
def native_dew_point (self ) -> float | None :
256
244
"""Return the dew point temperature in native units."""
@@ -265,11 +253,6 @@ def native_pressure(self) -> float | None:
265
253
DWD_MEASUREMENT_PRESSURE , ATTR_FORECAST_NATIVE_PRESSURE
266
254
)
267
255
268
- @property
269
- def native_pressure_unit (self ) -> str :
270
- """Return the native unit of measurement for pressure."""
271
- return UnitOfPressure .HPA
272
-
273
256
@property
274
257
def humidity (self ) -> float | None :
275
258
"""Return the humidity in native units."""
@@ -287,11 +270,6 @@ def native_visibility(self) -> float | None:
287
270
"""Return the visibility in native units."""
288
271
return self ._get_float_measurement_without_fallback (DWD_MEASUREMENT_VISIBILITY )
289
272
290
- @property
291
- def native_visibility_unit (self ) -> str :
292
- """Return the native unit of measurement for visibility."""
293
- return UnitOfLength .KILOMETERS
294
-
295
273
@property
296
274
def native_wind_gust_speed (self ) -> float | None :
297
275
"""Return the wind gust speed in native units."""
@@ -306,16 +284,6 @@ def native_wind_speed(self) -> float | None:
306
284
DWD_MEASUREMENT_MEANWIND_SPEED , ATTR_FORECAST_NATIVE_WIND_SPEED
307
285
)
308
286
309
- @property
310
- def native_wind_speed_unit (self ) -> str :
311
- """Return the native unit of measurement for wind speed."""
312
- return UnitOfSpeed .KILOMETERS_PER_HOUR
313
-
314
- @property
315
- def native_precipitation_unit (self ) -> str :
316
- """Return the native unit of measurement for accumulated precipitation."""
317
- return UnitOfLength .MILLIMETERS
318
-
319
287
@property
320
288
def wind_bearing (self ) -> float | None :
321
289
"""Return the wind bearing."""
@@ -370,11 +338,6 @@ def _get_float_measurement_without_fallback(
370
338
else :
371
339
return None
372
340
373
- @property
374
- def attribution (self ) -> str :
375
- """Return the attribution."""
376
- return ATTRIBUTION
377
-
378
341
@property
379
342
def forecast (self ):
380
343
"""Return the forecast array."""
0 commit comments