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:
parent
ab699d17a5
commit
a616ac2b60
11 changed files with 23 additions and 61 deletions
|
@ -19,7 +19,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
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__)
|
||||
|
||||
|
@ -54,6 +54,8 @@ async def async_setup_platform(
|
|||
class AmpioSmogQuality(AirQualityEntity):
|
||||
"""Implementation of an Ampio Smog air quality entity."""
|
||||
|
||||
_attr_attribution = "Data provided by Ampio"
|
||||
|
||||
def __init__(
|
||||
self, api: AmpioSmogMapData, station_id: str, name: str | None
|
||||
) -> None:
|
||||
|
@ -82,11 +84,6 @@ class AmpioSmogQuality(AirQualityEntity):
|
|||
"""Return the particulate matter 10 level."""
|
||||
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:
|
||||
"""Get the latest data from the AmpioMap API."""
|
||||
await self._ampio.async_update()
|
||||
|
|
|
@ -2,6 +2,5 @@
|
|||
from datetime import timedelta
|
||||
from typing import Final
|
||||
|
||||
ATTRIBUTION: Final = "Data provided by Ampio"
|
||||
CONF_STATION_ID: Final = "station_id"
|
||||
SCAN_INTERVAL: Final = timedelta(minutes=10)
|
||||
|
|
|
@ -35,9 +35,6 @@ from homeassistant.util.unit_system import METRIC_SYSTEM
|
|||
from . import MetDataUpdateCoordinator
|
||||
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"
|
||||
|
||||
|
||||
|
@ -74,6 +71,10 @@ def format_condition(condition: str) -> str:
|
|||
class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity):
|
||||
"""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_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||
|
@ -173,11 +174,6 @@ class MetWeather(CoordinatorEntity[MetDataUpdateCoordinator], WeatherEntity):
|
|||
ATTR_MAP[ATTR_WEATHER_WIND_BEARING]
|
||||
)
|
||||
|
||||
@property
|
||||
def attribution(self) -> str:
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
||||
@property
|
||||
def forecast(self) -> list[Forecast] | None:
|
||||
"""Return the forecast array."""
|
||||
|
|
|
@ -20,8 +20,6 @@ from homeassistant.components.weather import (
|
|||
DOMAIN as WEATHER_DOMAIN,
|
||||
)
|
||||
|
||||
ATTRIBUTION = "Data provided by Met Éireann"
|
||||
|
||||
DEFAULT_NAME = "Met Éireann"
|
||||
|
||||
DOMAIN = "met_eireann"
|
||||
|
|
|
@ -23,7 +23,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||
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__)
|
||||
|
||||
|
@ -55,6 +55,7 @@ async def async_setup_entry(
|
|||
class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
||||
"""Implementation of a Met Éireann weather condition."""
|
||||
|
||||
_attr_attribution = "Data provided by Met Éireann"
|
||||
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
@ -125,11 +126,6 @@ class MetEireannWeather(CoordinatorEntity, WeatherEntity):
|
|||
"""Return the wind direction."""
|
||||
return self.coordinator.data.current_weather_data.get("wind_bearing")
|
||||
|
||||
@property
|
||||
def attribution(self):
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
||||
@property
|
||||
def forecast(self):
|
||||
"""Return the forecast array."""
|
||||
|
|
|
@ -83,6 +83,7 @@ class MeteoFranceWeather(
|
|||
):
|
||||
"""Representation of a weather condition."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_attr_native_precipitation_unit = UnitOfPrecipitationDepth.MILLIMETERS
|
||||
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||
|
@ -203,8 +204,3 @@ class MeteoFranceWeather(
|
|||
}
|
||||
)
|
||||
return forecast_data
|
||||
|
||||
@property
|
||||
def attribution(self):
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
|
|
@ -38,6 +38,7 @@ async def async_setup_entry(
|
|||
class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
|
||||
"""Representation of a weather condition."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_native_pressure_unit = UnitOfPressure.HPA
|
||||
_attr_native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
_attr_native_wind_speed_unit = UnitOfSpeed.KILOMETERS_PER_HOUR
|
||||
|
@ -98,8 +99,3 @@ class MeteoclimaticWeather(CoordinatorEntity, WeatherEntity):
|
|||
def wind_bearing(self):
|
||||
"""Return the wind bearing."""
|
||||
return self.coordinator.data["weather"].wind_bearing
|
||||
|
||||
@property
|
||||
def attribution(self):
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
|
|
@ -39,7 +39,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
ATTR_AREA = "area"
|
||||
ATTR_POLLUTION_INDEX = "nilu_pollution_index"
|
||||
ATTRIBUTION = "Data provided by luftkvalitet.info and nilu.no"
|
||||
|
||||
CONF_AREA = "area"
|
||||
CONF_STATION = "stations"
|
||||
|
@ -173,6 +172,8 @@ class NiluData:
|
|||
class NiluSensor(AirQualityEntity):
|
||||
"""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:
|
||||
"""Initialize the sensor."""
|
||||
self._api = api_data
|
||||
|
@ -184,11 +185,6 @@ class NiluSensor(AirQualityEntity):
|
|||
self._attrs[CONF_LATITUDE] = api_data.data.latitude
|
||||
self._attrs[CONF_LONGITUDE] = api_data.data.longitude
|
||||
|
||||
@property
|
||||
def attribution(self) -> str:
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
"""Return other details about the sensor state."""
|
||||
|
|
|
@ -17,12 +17,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|||
|
||||
_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"
|
||||
|
||||
|
@ -81,6 +75,13 @@ def round_state(func):
|
|||
class AirSensor(AirQualityEntity):
|
||||
"""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):
|
||||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
|
@ -88,11 +89,6 @@ class AirSensor(AirQualityEntity):
|
|||
coordinates, forecast, session, api_url=OVERRIDE_URL
|
||||
)
|
||||
|
||||
@property
|
||||
def attribution(self) -> str:
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self) -> dict:
|
||||
"""Return other details about the sensor state."""
|
||||
|
|
|
@ -108,6 +108,7 @@ if TYPE_CHECKING:
|
|||
class NWSWeather(WeatherEntity):
|
||||
"""Representation of a weather condition."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(
|
||||
|
@ -154,11 +155,6 @@ class NWSWeather(WeatherEntity):
|
|||
|
||||
self.async_write_ha_state()
|
||||
|
||||
@property
|
||||
def attribution(self) -> str:
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the station."""
|
||||
|
|
|
@ -20,7 +20,6 @@ from homeassistant.util import Throttle
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTRIBUTION = "Data provided by openSenseMap"
|
||||
|
||||
CONF_STATION_ID = "station_id"
|
||||
|
||||
|
@ -59,6 +58,8 @@ async def async_setup_platform(
|
|||
class OpenSenseMapQuality(AirQualityEntity):
|
||||
"""Implementation of an openSenseMap air quality entity."""
|
||||
|
||||
_attr_attribution = "Data provided by openSenseMap"
|
||||
|
||||
def __init__(self, name, osm):
|
||||
"""Initialize the air quality entity."""
|
||||
self._name = name
|
||||
|
@ -79,11 +80,6 @@ class OpenSenseMapQuality(AirQualityEntity):
|
|||
"""Return the particulate matter 10 level."""
|
||||
return self._osm.api.pm10
|
||||
|
||||
@property
|
||||
def attribution(self):
|
||||
"""Return the attribution."""
|
||||
return ATTRIBUTION
|
||||
|
||||
async def async_update(self):
|
||||
"""Get the latest data from the openSenseMap API."""
|
||||
await self._osm.async_update()
|
||||
|
|
Loading…
Add table
Reference in a new issue