From 8bca984d61b38ae286b34d2f0ca97e87c30249aa Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Sun, 19 Dec 2021 13:25:51 +0100 Subject: [PATCH] Use _attr_** in openweathermap (#62179) Co-authored-by: epenet --- .../components/openweathermap/sensor.py | 8 +--- .../components/openweathermap/weather.py | 43 ++++--------------- 2 files changed, 10 insertions(+), 41 deletions(-) diff --git a/homeassistant/components/openweathermap/sensor.py b/homeassistant/components/openweathermap/sensor.py index 4a34069e036..20ee621b9dc 100644 --- a/homeassistant/components/openweathermap/sensor.py +++ b/homeassistant/components/openweathermap/sensor.py @@ -9,7 +9,6 @@ from homeassistant.components.sensor import ( SensorEntityDescription, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.entity import DeviceInfo @@ -71,7 +70,7 @@ class AbstractOpenWeatherMapSensor(SensorEntity): """Abstract class for an OpenWeatherMap sensor.""" _attr_should_poll = False - _attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION} + _attr_attribution = ATTRIBUTION def __init__( self, @@ -94,11 +93,6 @@ class AbstractOpenWeatherMapSensor(SensorEntity): name=DEFAULT_NAME, ) - @property - def attribution(self) -> str: - """Return the attribution.""" - return ATTRIBUTION - @property def available(self) -> bool: """Return True if entity is available.""" diff --git a/homeassistant/components/openweathermap/weather.py b/homeassistant/components/openweathermap/weather.py index aafa1a9c808..d4ab99bc30b 100644 --- a/homeassistant/components/openweathermap/weather.py +++ b/homeassistant/components/openweathermap/weather.py @@ -47,6 +47,10 @@ async def async_setup_entry( class OpenWeatherMapWeather(WeatherEntity): """Implementation of an OpenWeatherMap sensor.""" + _attr_attribution = ATTRIBUTION + _attr_should_poll = False + _attr_temperature_unit = TEMP_CELSIUS + def __init__( self, name: str, @@ -54,39 +58,15 @@ class OpenWeatherMapWeather(WeatherEntity): weather_coordinator: WeatherUpdateCoordinator, ) -> None: """Initialize the sensor.""" - self._name = name - self._unique_id = unique_id - self._weather_coordinator = weather_coordinator - - @property - def name(self) -> str: - """Return the name of the sensor.""" - return self._name - - @property - def unique_id(self) -> str: - """Return a unique_id for this entity.""" - return self._unique_id - - @property - def device_info(self) -> DeviceInfo: - """Return the device info.""" - return DeviceInfo( + self._attr_name = name + self._attr_unique_id = unique_id + self._attr_device_info = DeviceInfo( entry_type=DeviceEntryType.SERVICE, - identifiers={(DOMAIN, self._unique_id)}, + identifiers={(DOMAIN, unique_id)}, manufacturer=MANUFACTURER, name=DEFAULT_NAME, ) - - @property - def should_poll(self) -> bool: - """Return the polling requirement of the entity.""" - return False - - @property - def attribution(self) -> str: - """Return the attribution.""" - return ATTRIBUTION + self._weather_coordinator = weather_coordinator @property def condition(self) -> str | None: @@ -98,11 +78,6 @@ class OpenWeatherMapWeather(WeatherEntity): """Return the temperature.""" return self._weather_coordinator.data[ATTR_API_TEMPERATURE] - @property - def temperature_unit(self) -> str: - """Return the unit of measurement.""" - return TEMP_CELSIUS - @property def pressure(self) -> float | None: """Return the pressure."""