Move attribution constants to entity attributes (#90519)

* Move attribution constants to entity attributes

* Adjust meteo france

* Adjust meteoclimatic

* Adjust nws
This commit is contained in:
epenet 2023-03-31 14:25:49 +02:00 committed by GitHub
parent ab699d17a5
commit a616ac2b60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 23 additions and 61 deletions

View file

@ -19,7 +19,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import Throttle from homeassistant.util import Throttle
from .const import ATTRIBUTION, CONF_STATION_ID, SCAN_INTERVAL from .const import CONF_STATION_ID, SCAN_INTERVAL
_LOGGER: Final = logging.getLogger(__name__) _LOGGER: Final = logging.getLogger(__name__)
@ -54,6 +54,8 @@ async def async_setup_platform(
class AmpioSmogQuality(AirQualityEntity): class AmpioSmogQuality(AirQualityEntity):
"""Implementation of an Ampio Smog air quality entity.""" """Implementation of an Ampio Smog air quality entity."""
_attr_attribution = "Data provided by Ampio"
def __init__( def __init__(
self, api: AmpioSmogMapData, station_id: str, name: str | None self, api: AmpioSmogMapData, station_id: str, name: str | None
) -> None: ) -> None:
@ -82,11 +84,6 @@ class AmpioSmogQuality(AirQualityEntity):
"""Return the particulate matter 10 level.""" """Return the particulate matter 10 level."""
return self._ampio.api.pm10 # type: ignore[no-any-return] return self._ampio.api.pm10 # type: ignore[no-any-return]
@property
def attribution(self) -> str:
"""Return the attribution."""
return ATTRIBUTION
async def async_update(self) -> None: async def async_update(self) -> None:
"""Get the latest data from the AmpioMap API.""" """Get the latest data from the AmpioMap API."""
await self._ampio.async_update() await self._ampio.async_update()

View file

@ -2,6 +2,5 @@
from datetime import timedelta from datetime import timedelta
from typing import Final from typing import Final
ATTRIBUTION: Final = "Data provided by Ampio"
CONF_STATION_ID: Final = "station_id" CONF_STATION_ID: Final = "station_id"
SCAN_INTERVAL: Final = timedelta(minutes=10) SCAN_INTERVAL: Final = timedelta(minutes=10)

View file

@ -35,9 +35,6 @@ from homeassistant.util.unit_system import METRIC_SYSTEM
from . import MetDataUpdateCoordinator from . import MetDataUpdateCoordinator
from .const import ATTR_MAP, CONDITIONS_MAP, CONF_TRACK_HOME, DOMAIN, FORECAST_MAP from .const import ATTR_MAP, CONDITIONS_MAP, CONF_TRACK_HOME, DOMAIN, FORECAST_MAP
ATTRIBUTION = (
"Weather forecast from met.no, delivered by the Norwegian Meteorological Institute."
)
DEFAULT_NAME = "Met.no" DEFAULT_NAME = "Met.no"
@ -74,6 +71,10 @@ def format_condition(condition: str) -> str:
class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity): class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity):
"""Implementation of a Met.no weather condition.""" """Implementation of a Met.no weather condition."""
_attr_attribution = (
"Weather forecast from met.no, delivered by the Norwegian "
"Meteorological Institute."
)
_attr_has_entity_name = True _attr_has_entity_name = True
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
@ -173,11 +174,6 @@ class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity):
ATTR_MAP[ATTR_WEATHER_WIND_BEARING] ATTR_MAP[ATTR_WEATHER_WIND_BEARING]
) )
@property
def attribution(self) -> str:
"""Return the attribution."""
return ATTRIBUTION
@property @property
def forecast(self) -> list[Forecast] | None: def forecast(self) -> list[Forecast] | None:
"""Return the forecast array.""" """Return the forecast array."""

View file

@ -20,8 +20,6 @@ from homeassistant.components.weather import (
DOMAIN as WEATHER_DOMAIN, DOMAIN as WEATHER_DOMAIN,
) )
ATTRIBUTION = "Data provided by Met Éireann"
DEFAULT_NAME = "Met Éireann" DEFAULT_NAME = "Met Éireann"
DOMAIN = "met_eireann" DOMAIN = "met_eireann"

View file

@ -23,7 +23,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util import dt as dt_util from homeassistant.util import dt as dt_util
from .const import ATTRIBUTION, CONDITION_MAP, DEFAULT_NAME, DOMAIN, FORECAST_MAP from .const import CONDITION_MAP, DEFAULT_NAME, DOMAIN, FORECAST_MAP
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -55,6 +55,7 @@ async def async_setup_entry(
class MetEireannWeather(CoordinatorEntity, WeatherEntity): class MetEireannWeather(CoordinatorEntity, WeatherEntity):
"""Implementation of a Met Éireann weather condition.""" """Implementation of a Met Éireann weather condition."""
_attr_attribution = "Data provided by Met Éireann"
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
_attr_native_pressure_unit = UnitOfPressure.HPA _attr_native_pressure_unit = UnitOfPressure.HPA
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
@ -125,11 +126,6 @@ class MetEireannWeather(CoordinatorEntity, WeatherEntity):
"""Return the wind direction.""" """Return the wind direction."""
return self.coordinator.data.current_weather_data.get("wind_bearing") return self.coordinator.data.current_weather_data.get("wind_bearing")
@property
def attribution(self):
"""Return the attribution."""
return ATTRIBUTION
@property @property
def forecast(self): def forecast(self):
"""Return the forecast array.""" """Return the forecast array."""

View file

@ -83,6 +83,7 @@ class MeteoFranceWeather(
): ):
"""Representation of a weather condition.""" """Representation of a weather condition."""
_attr_attribution = ATTRIBUTION
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS _attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
_attr_native_pressure_unit = UnitOfPressure.HPA _attr_native_pressure_unit = UnitOfPressure.HPA
@ -203,8 +204,3 @@ class MeteoFranceWeather(
} }
) )
return forecast_data return forecast_data
@property
def attribution(self):
"""Return the attribution."""
return ATTRIBUTION

View file

@ -38,6 +38,7 @@ async def async_setup_entry(
class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity): class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
"""Representation of a weather condition.""" """Representation of a weather condition."""
_attr_attribution = ATTRIBUTION
_attr_native_pressure_unit = UnitOfPressure.HPA _attr_native_pressure_unit = UnitOfPressure.HPA
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS _attr_native_temperature_unit = UnitOfTemperature.CELSIUS
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR _attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
@ -98,8 +99,3 @@ class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
def wind_bearing(self): def wind_bearing(self):
"""Return the wind bearing.""" """Return the wind bearing."""
return self.coordinator.data["weather"].wind_bearing return self.coordinator.data["weather"].wind_bearing
@property
def attribution(self):
"""Return the attribution."""
return ATTRIBUTION

View file

@ -39,7 +39,6 @@ _LOGGER = logging.getLogger(__name__)
ATTR_AREA = "area" ATTR_AREA = "area"
ATTR_POLLUTION_INDEX = "nilu_pollution_index" ATTR_POLLUTION_INDEX = "nilu_pollution_index"
ATTRIBUTION = "Data provided by luftkvalitet.info and nilu.no"
CONF_AREA = "area" CONF_AREA = "area"
CONF_STATION = "stations" CONF_STATION = "stations"
@ -173,6 +172,8 @@ class NiluData:
class NiluSensor(AirQualityEntity): class NiluSensor(AirQualityEntity):
"""Single nilu station air sensor.""" """Single nilu station air sensor."""
_attr_attribution = "Data provided by luftkvalitet.info and nilu.no"
def __init__(self, api_data: NiluData, name: str, show_on_map: bool) -> None: def __init__(self, api_data: NiluData, name: str, show_on_map: bool) -> None:
"""Initialize the sensor.""" """Initialize the sensor."""
self._api = api_data self._api = api_data
@ -184,11 +185,6 @@ class NiluSensor(AirQualityEntity):
self._attrs[CONF_LATITUDE] = api_data.data.latitude self._attrs[CONF_LATITUDE] = api_data.data.latitude
self._attrs[CONF_LONGITUDE] = api_data.data.longitude self._attrs[CONF_LONGITUDE] = api_data.data.longitude
@property
def attribution(self) -> str:
"""Return the attribution."""
return ATTRIBUTION
@property @property
def extra_state_attributes(self) -> dict: def extra_state_attributes(self) -> dict:
"""Return other details about the sensor state.""" """Return other details about the sensor state."""

View file

@ -17,12 +17,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ATTRIBUTION = (
"Air quality from "
"https://luftkvalitet.miljostatus.no/, "
"delivered by the Norwegian Meteorological Institute."
)
# https://api.met.no/license_data.html
CONF_FORECAST = "forecast" CONF_FORECAST = "forecast"
@ -81,6 +75,13 @@ def round_state(func):
class AirSensor(AirQualityEntity): class AirSensor(AirQualityEntity):
"""Representation of an air quality sensor.""" """Representation of an air quality sensor."""
# https://api.met.no/license_data.html
_attr_attribution = (
"Air quality from "
"https://luftkvalitet.miljostatus.no/, "
"delivered by the Norwegian Meteorological Institute."
)
def __init__(self, name, coordinates, forecast, session): def __init__(self, name, coordinates, forecast, session):
"""Initialize the sensor.""" """Initialize the sensor."""
self._name = name self._name = name
@ -88,11 +89,6 @@ class AirSensor(AirQualityEntity):
coordinates, forecast, session, api_url=OVERRIDE_URL coordinates, forecast, session, api_url=OVERRIDE_URL
) )
@property
def attribution(self) -> str:
"""Return the attribution."""
return ATTRIBUTION
@property @property
def extra_state_attributes(self) -> dict: def extra_state_attributes(self) -> dict:
"""Return other details about the sensor state.""" """Return other details about the sensor state."""

View file

@ -108,6 +108,7 @@ if TYPE_CHECKING:
class NWSWeather(WeatherEntity): class NWSWeather(WeatherEntity):
"""Representation of a weather condition.""" """Representation of a weather condition."""
_attr_attribution = ATTRIBUTION
_attr_should_poll = False _attr_should_poll = False
def __init__( def __init__(
@ -154,11 +155,6 @@ class NWSWeather(WeatherEntity):
self.async_write_ha_state() self.async_write_ha_state()
@property
def attribution(self) -> str:
"""Return the attribution."""
return ATTRIBUTION
@property @property
def name(self) -> str: def name(self) -> str:
"""Return the name of the station.""" """Return the name of the station."""

View file

@ -20,7 +20,6 @@ from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by openSenseMap"
CONF_STATION_ID = "station_id" CONF_STATION_ID = "station_id"
@ -59,6 +58,8 @@ async def async_setup_platform(
class OpenSenseMapQuality(AirQualityEntity): class OpenSenseMapQuality(AirQualityEntity):
"""Implementation of an openSenseMap air quality entity.""" """Implementation of an openSenseMap air quality entity."""
_attr_attribution = "Data provided by openSenseMap"
def __init__(self, name, osm): def __init__(self, name, osm):
"""Initialize the air quality entity.""" """Initialize the air quality entity."""
self._name = name self._name = name
@ -79,11 +80,6 @@ class OpenSenseMapQuality(AirQualityEntity):
"""Return the particulate matter 10 level.""" """Return the particulate matter 10 level."""
return self._osm.api.pm10 return self._osm.api.pm10
@property
def attribution(self):
"""Return the attribution."""
return ATTRIBUTION
async def async_update(self): async def async_update(self):
"""Get the latest data from the openSenseMap API.""" """Get the latest data from the openSenseMap API."""
await self._osm.async_update() await self._osm.async_update()