diff --git a/homeassistant/components/tankerkoenig/sensor.py b/homeassistant/components/tankerkoenig/sensor.py index c63b0ea0e7e..e3b2ca9554b 100644 --- a/homeassistant/components/tankerkoenig/sensor.py +++ b/homeassistant/components/tankerkoenig/sensor.py @@ -5,12 +5,7 @@ import logging from homeassistant.components.sensor import SensorEntity, SensorStateClass from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - ATTR_ATTRIBUTION, - ATTR_LATITUDE, - ATTR_LONGITUDE, - CURRENCY_EURO, -) +from homeassistant.const import ATTR_LATITUDE, ATTR_LONGITUDE, CURRENCY_EURO from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -62,6 +57,7 @@ async def async_setup_entry( class FuelPriceSensor(TankerkoenigCoordinatorEntity, SensorEntity): """Contains prices for fuel in a given station.""" + _attr_attribution = ATTRIBUTION _attr_state_class = SensorStateClass.MEASUREMENT _attr_icon = "mdi:gas-station" @@ -74,7 +70,6 @@ class FuelPriceSensor(TankerkoenigCoordinatorEntity, SensorEntity): self._attr_native_unit_of_measurement = CURRENCY_EURO self._attr_unique_id = f"{station['id']}_{fuel_type}" attrs = { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_BRAND: station["brand"], ATTR_FUEL_TYPE: fuel_type, ATTR_STATION_NAME: station["name"], diff --git a/homeassistant/components/tmb/sensor.py b/homeassistant/components/tmb/sensor.py index 8d6db00b2b9..cd9453ed430 100644 --- a/homeassistant/components/tmb/sensor.py +++ b/homeassistant/components/tmb/sensor.py @@ -9,7 +9,7 @@ from tmb import IBus import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, TIME_MINUTES +from homeassistant.const import CONF_NAME, TIME_MINUTES from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -18,8 +18,6 @@ from homeassistant.util import Throttle _LOGGER = logging.getLogger(__name__) -ATTRIBUTION = "Data provided by Transport Metropolitans de Barcelona" - ICON = "mdi:bus-clock" CONF_APP_ID = "app_id" @@ -75,6 +73,8 @@ def setup_platform( class TMBSensor(SensorEntity): """Implementation of a TMB line/stop Sensor.""" + _attr_attribution = "Data provided by Transport Metropolitans de Barcelona" + def __init__(self, ibus_client, stop, line, name): """Initialize the sensor.""" self._ibus_client = ibus_client @@ -113,7 +113,6 @@ class TMBSensor(SensorEntity): def extra_state_attributes(self): """Return the state attributes of the last update.""" return { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_BUS_STOP: self._stop, ATTR_LINE: self._line, } diff --git a/homeassistant/components/tomorrowio/__init__.py b/homeassistant/components/tomorrowio/__init__.py index 956b0901dd7..e2aaba6cdff 100644 --- a/homeassistant/components/tomorrowio/__init__.py +++ b/homeassistant/components/tomorrowio/__init__.py @@ -320,6 +320,8 @@ class TomorrowioDataUpdateCoordinator(DataUpdateCoordinator): class TomorrowioEntity(CoordinatorEntity[TomorrowioDataUpdateCoordinator]): """Base Tomorrow.io Entity.""" + _attr_attribution = ATTRIBUTION + def __init__( self, config_entry: ConfigEntry, @@ -346,8 +348,3 @@ class TomorrowioEntity(CoordinatorEntity[TomorrowioDataUpdateCoordinator]): """ entry_id = self._config_entry.entry_id return self.coordinator.data[entry_id].get(CURRENT, {}).get(property_name) - - @property - def attribution(self): - """Return the attribution.""" - return ATTRIBUTION diff --git a/homeassistant/components/tomorrowio/sensor.py b/homeassistant/components/tomorrowio/sensor.py index 1f3bb74b686..78c973fd80b 100644 --- a/homeassistant/components/tomorrowio/sensor.py +++ b/homeassistant/components/tomorrowio/sensor.py @@ -20,7 +20,6 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONCENTRATION_PARTS_PER_MILLION, CONF_API_KEY, @@ -326,7 +325,6 @@ class BaseTomorrowioSensorEntity(TomorrowioEntity, SensorEntity): self._attr_unique_id = ( f"{self._config_entry.unique_id}_{slugify(description.name)}" ) - self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: self.attribution} if self.entity_description.native_unit_of_measurement is None: self._attr_native_unit_of_measurement = description.unit_metric if hass.config.units is IMPERIAL_SYSTEM: diff --git a/homeassistant/components/transport_nsw/sensor.py b/homeassistant/components/transport_nsw/sensor.py index 27fd6fd67fd..116dd5c0923 100644 --- a/homeassistant/components/transport_nsw/sensor.py +++ b/homeassistant/components/transport_nsw/sensor.py @@ -7,13 +7,7 @@ from TransportNSW import TransportNSW import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ( - ATTR_ATTRIBUTION, - ATTR_MODE, - CONF_API_KEY, - CONF_NAME, - TIME_MINUTES, -) +from homeassistant.const import ATTR_MODE, CONF_API_KEY, CONF_NAME, TIME_MINUTES from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -26,8 +20,6 @@ ATTR_DELAY = "delay" ATTR_REAL_TIME = "real_time" ATTR_DESTINATION = "destination" -ATTRIBUTION = "Data provided by Transport NSW" - CONF_STOP_ID = "stop_id" CONF_ROUTE = "route" CONF_DESTINATION = "destination" @@ -77,6 +69,8 @@ def setup_platform( class TransportNSWSensor(SensorEntity): """Implementation of an Transport NSW sensor.""" + _attr_attribution = "Data provided by Transport NSW" + def __init__(self, data, stop_id, name): """Initialize the sensor.""" self.data = data @@ -107,7 +101,6 @@ class TransportNSWSensor(SensorEntity): ATTR_REAL_TIME: self._times[ATTR_REAL_TIME], ATTR_DESTINATION: self._times[ATTR_DESTINATION], ATTR_MODE: self._times[ATTR_MODE], - ATTR_ATTRIBUTION: ATTRIBUTION, } @property diff --git a/homeassistant/components/travisci/sensor.py b/homeassistant/components/travisci/sensor.py index c35391d4573..ab1cd4a6b03 100644 --- a/homeassistant/components/travisci/sensor.py +++ b/homeassistant/components/travisci/sensor.py @@ -15,7 +15,6 @@ from homeassistant.components.sensor import ( SensorEntityDescription, ) from homeassistant.const import ( - ATTR_ATTRIBUTION, CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_SCAN_INTERVAL, @@ -28,8 +27,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType _LOGGER = logging.getLogger(__name__) -ATTRIBUTION = "Information provided by https://travis-ci.org/" - CONF_BRANCH = "branch" CONF_REPOSITORY = "repository" @@ -142,6 +139,8 @@ def setup_platform( class TravisCISensor(SensorEntity): """Representation of a Travis CI sensor.""" + _attr_attribution = "Information provided by https://travis-ci.org/" + def __init__( self, data, repo_name, user, branch, description: SensorEntityDescription ): @@ -159,7 +158,6 @@ class TravisCISensor(SensorEntity): def extra_state_attributes(self): """Return the state attributes.""" attrs = {} - attrs[ATTR_ATTRIBUTION] = ATTRIBUTION if self._build and self._attr_native_value is not None: if self._user and self.entity_description.key == "state": diff --git a/homeassistant/components/vasttrafik/sensor.py b/homeassistant/components/vasttrafik/sensor.py index d4229066eff..118d04d3c1b 100644 --- a/homeassistant/components/vasttrafik/sensor.py +++ b/homeassistant/components/vasttrafik/sensor.py @@ -8,7 +8,7 @@ import vasttrafik import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ATTR_ATTRIBUTION, CONF_DELAY, CONF_NAME +from homeassistant.const import CONF_DELAY, CONF_NAME from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -22,7 +22,6 @@ ATTR_ACCESSIBILITY = "accessibility" ATTR_DIRECTION = "direction" ATTR_LINE = "line" ATTR_TRACK = "track" -ATTRIBUTION = "Data provided by Västtrafik" CONF_DEPARTURES = "departures" CONF_FROM = "from" @@ -83,6 +82,8 @@ def setup_platform( class VasttrafikDepartureSensor(SensorEntity): """Implementation of a Vasttrafik Departure Sensor.""" + _attr_attribution = "Data provided by Västtrafik" + def __init__(self, planner, name, departure, heading, lines, delay): """Initialize the sensor.""" self._planner = planner @@ -158,7 +159,6 @@ class VasttrafikDepartureSensor(SensorEntity): params = { ATTR_ACCESSIBILITY: departure.get("accessibility"), - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_DIRECTION: departure.get("direction"), ATTR_LINE: departure.get("sname"), ATTR_TRACK: departure.get("track"), diff --git a/homeassistant/components/viaggiatreno/sensor.py b/homeassistant/components/viaggiatreno/sensor.py index acb6ffa647e..bdc8909da0f 100644 --- a/homeassistant/components/viaggiatreno/sensor.py +++ b/homeassistant/components/viaggiatreno/sensor.py @@ -11,7 +11,7 @@ import async_timeout import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ATTR_ATTRIBUTION, TIME_MINUTES +from homeassistant.const import TIME_MINUTES from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession import homeassistant.helpers.config_validation as cv @@ -20,8 +20,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType _LOGGER = logging.getLogger(__name__) -ATTRIBUTION = "Powered by ViaggiaTreno Data" - VIAGGIATRENO_ENDPOINT = ( "http://www.viaggiatreno.it/infomobilita/" "resteasy/viaggiatreno/andamentoTreno/" @@ -96,6 +94,8 @@ async def async_http_request(hass, uri): class ViaggiaTrenoSensor(SensorEntity): """Implementation of a ViaggiaTreno sensor.""" + _attr_attribution = "Powered by ViaggiaTreno Data" + def __init__(self, train_id, station_id, name): """Initialize the sensor.""" self._state = None @@ -132,7 +132,6 @@ class ViaggiaTrenoSensor(SensorEntity): @property def extra_state_attributes(self): """Return extra attributes.""" - self._attributes[ATTR_ATTRIBUTION] = ATTRIBUTION return self._attributes @staticmethod diff --git a/homeassistant/components/waze_travel_time/sensor.py b/homeassistant/components/waze_travel_time/sensor.py index c4ff489cadf..67081aeab5f 100644 --- a/homeassistant/components/waze_travel_time/sensor.py +++ b/homeassistant/components/waze_travel_time/sensor.py @@ -13,7 +13,6 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, CONF_NAME, CONF_REGION, EVENT_HOMEASSISTANT_STARTED, @@ -115,6 +114,7 @@ async def async_setup_entry( class WazeTravelTime(SensorEntity): """Representation of a Waze travel time sensor.""" + _attr_attribution = "Powered by Waze" _attr_native_unit_of_measurement = TIME_MINUTES _attr_device_class = SensorDeviceClass.DURATION _attr_state_class = SensorStateClass.MEASUREMENT @@ -159,7 +159,6 @@ class WazeTravelTime(SensorEntity): return None return { - ATTR_ATTRIBUTION: "Powered by Waze", "duration": self._waze_data.duration, "distance": self._waze_data.distance, "route": self._waze_data.route, diff --git a/homeassistant/components/yandex_transport/sensor.py b/homeassistant/components/yandex_transport/sensor.py index 3fdca47ef02..b7a846bbc67 100644 --- a/homeassistant/components/yandex_transport/sensor.py +++ b/homeassistant/components/yandex_transport/sensor.py @@ -12,7 +12,7 @@ from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, ) -from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME +from homeassistant.const import CONF_NAME from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_create_clientsession import homeassistant.helpers.config_validation as cv @@ -24,7 +24,6 @@ _LOGGER = logging.getLogger(__name__) STOP_NAME = "stop_name" USER_AGENT = "Home Assistant" -ATTRIBUTION = "Data provided by maps.yandex.ru" CONF_STOP_ID = "stop_id" CONF_ROUTE = "routes" @@ -70,6 +69,8 @@ async def async_setup_platform( class DiscoverYandexTransport(SensorEntity): """Implementation of yandex_transport sensor.""" + _attr_attribution = "Data provided by maps.yandex.ru" + def __init__(self, requester: YandexMapsRequester, stop_id, routes, name): """Initialize sensor.""" self.requester = requester @@ -138,7 +139,7 @@ class DiscoverYandexTransport(SensorEntity): attrs[route] = [] attrs[route].append(departure["text"]) attrs[STOP_NAME] = stop_name - attrs[ATTR_ATTRIBUTION] = ATTRIBUTION + if closer_time is None: self._state = None else: