Use shorthand atts for met_eireann (#100335)

This commit is contained in:
Jan Bouwhuis 2023-09-14 00:11:27 +02:00 committed by GitHub
parent a02fcbc5c4
commit a7c6abfed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,24 +94,20 @@ class MetEireannWeather(
self._attr_unique_id = _calculate_unique_id(config, hourly) self._attr_unique_id = _calculate_unique_id(config, hourly)
self._config = config self._config = config
self._hourly = hourly self._hourly = hourly
name_appendix = " Hourly" if hourly else ""
@property if (name := self._config.get(CONF_NAME)) is not None:
def name(self): self._attr_name = f"{name}{name_appendix}"
"""Return the name of the sensor.""" else:
name = self._config.get(CONF_NAME) self._attr_name = f"{DEFAULT_NAME}{name_appendix}"
name_appendix = "" self._attr_entity_registry_enabled_default = not hourly
if self._hourly: self._attr_device_info = DeviceInfo(
name_appendix = " Hourly" name="Forecast",
entry_type=DeviceEntryType.SERVICE,
if name is not None: identifiers={(DOMAIN,)},
return f"{name}{name_appendix}" manufacturer="Met Éireann",
model="Forecast",
return f"{DEFAULT_NAME}{name_appendix}" configuration_url="https://www.met.ie",
)
@property
def entity_registry_enabled_default(self) -> bool:
"""Return if the entity should be enabled when first added to the entity registry."""
return not self._hourly
@property @property
def condition(self): def condition(self):
@ -191,15 +187,3 @@ class MetEireannWeather(
def _async_forecast_hourly(self) -> list[Forecast]: def _async_forecast_hourly(self) -> list[Forecast]:
"""Return the hourly forecast in native units.""" """Return the hourly forecast in native units."""
return self._forecast(True) return self._forecast(True)
@property
def device_info(self):
"""Device info."""
return DeviceInfo(
name="Forecast",
entry_type=DeviceEntryType.SERVICE,
identifiers={(DOMAIN,)},
manufacturer="Met Éireann",
model="Forecast",
configuration_url="https://www.met.ie",
)