diff --git a/homeassistant/components/eafm/sensor.py b/homeassistant/components/eafm/sensor.py index ed663920a80..a695a38bb4b 100644 --- a/homeassistant/components/eafm/sensor.py +++ b/homeassistant/components/eafm/sensor.py @@ -7,7 +7,7 @@ import async_timeout from homeassistant.components.sensor import SensorEntity, SensorStateClass from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION, LENGTH_METERS +from homeassistant.const import LENGTH_METERS from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.device_registry import DeviceEntryType @@ -90,7 +90,10 @@ async def async_setup_entry( class Measurement(CoordinatorEntity, SensorEntity): """A gauge at a flood monitoring station.""" - attribution = "This uses Environment Agency flood and river level data from the real-time data API" + _attr_attribution = ( + "This uses Environment Agency flood and river level data " + "from the real-time data API" + ) _attr_state_class = SensorStateClass.MEASUREMENT def __init__(self, coordinator, key): @@ -166,11 +169,6 @@ class Measurement(CoordinatorEntity, SensorEntity): return None return UNIT_MAPPING.get(measure["unit"], measure["unitName"]) - @property - def extra_state_attributes(self): - """Return the sensor specific state attributes.""" - return {ATTR_ATTRIBUTION: self.attribution} - @property def native_value(self): """Return the current sensor value.""" diff --git a/homeassistant/components/entur_public_transport/sensor.py b/homeassistant/components/entur_public_transport/sensor.py index e980ef0e396..fd470ff7c9f 100644 --- a/homeassistant/components/entur_public_transport/sensor.py +++ b/homeassistant/components/entur_public_transport/sensor.py @@ -8,7 +8,6 @@ import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity from homeassistant.const import ( - ATTR_ATTRIBUTION, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, @@ -25,8 +24,6 @@ import homeassistant.util.dt as dt_util API_CLIENT_NAME = "homeassistant-homeassistant" -ATTRIBUTION = "Data provided by entur.org under NLOD" - CONF_STOP_IDS = "stop_ids" CONF_EXPAND_PLATFORMS = "expand_platforms" CONF_WHITELIST_LINES = "line_whitelist" @@ -160,6 +157,8 @@ class EnturProxy: class EnturPublicTransportSensor(SensorEntity): """Implementation of a Entur public transport sensor.""" + _attr_attribution = "Data provided by entur.org under NLOD" + def __init__( self, api: EnturProxy, name: str, stop: str, show_on_map: bool ) -> None: @@ -185,7 +184,6 @@ class EnturPublicTransportSensor(SensorEntity): @property def extra_state_attributes(self) -> dict: """Return the state attributes.""" - self._attributes[ATTR_ATTRIBUTION] = ATTRIBUTION self._attributes[ATTR_STOP_ID] = self._stop return self._attributes diff --git a/homeassistant/components/etherscan/sensor.py b/homeassistant/components/etherscan/sensor.py index 9f0c6f7eca9..d98ddcba23c 100644 --- a/homeassistant/components/etherscan/sensor.py +++ b/homeassistant/components/etherscan/sensor.py @@ -7,14 +7,12 @@ from pyetherscan import get_balance import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ATTR_ATTRIBUTION, CONF_ADDRESS, CONF_NAME, CONF_TOKEN +from homeassistant.const import CONF_ADDRESS, CONF_NAME, CONF_TOKEN from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType -ATTRIBUTION = "Data provided by etherscan.io" - CONF_TOKEN_ADDRESS = "token_address" SCAN_INTERVAL = timedelta(minutes=5) @@ -54,6 +52,8 @@ def setup_platform( class EtherscanSensor(SensorEntity): """Representation of an Etherscan.io sensor.""" + _attr_attribution = "Data provided by etherscan.io" + def __init__(self, name, address, token, token_address): """Initialize the sensor.""" self._name = name @@ -78,11 +78,6 @@ class EtherscanSensor(SensorEntity): """Return the unit of measurement this sensor expresses itself in.""" return self._unit_of_measurement - @property - def extra_state_attributes(self): - """Return the state attributes of the sensor.""" - return {ATTR_ATTRIBUTION: ATTRIBUTION} - def update(self) -> None: """Get the latest state of the sensor.""" diff --git a/homeassistant/components/fitbit/sensor.py b/homeassistant/components/fitbit/sensor.py index c4e9970691d..78929307c02 100644 --- a/homeassistant/components/fitbit/sensor.py +++ b/homeassistant/components/fitbit/sensor.py @@ -19,12 +19,7 @@ from homeassistant.components.sensor import ( PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA, SensorEntity, ) -from homeassistant.const import ( - ATTR_ATTRIBUTION, - CONF_CLIENT_ID, - CONF_CLIENT_SECRET, - CONF_UNIT_SYSTEM, -) +from homeassistant.const import CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_UNIT_SYSTEM from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -345,6 +340,7 @@ class FitbitSensor(SensorEntity): """Implementation of a Fitbit sensor.""" entity_description: FitbitSensorEntityDescription + _attr_attribution = ATTRIBUTION def __init__( self, @@ -396,7 +392,7 @@ class FitbitSensor(SensorEntity): @property def extra_state_attributes(self) -> dict[str, str | None]: """Return the state attributes.""" - attrs: dict[str, str | None] = {ATTR_ATTRIBUTION: ATTRIBUTION} + attrs: dict[str, str | None] = {} if self.extra is not None: attrs["model"] = self.extra.get("deviceVersion") diff --git a/homeassistant/components/flick_electric/sensor.py b/homeassistant/components/flick_electric/sensor.py index 215c9a88f6b..d0ff91d7094 100644 --- a/homeassistant/components/flick_electric/sensor.py +++ b/homeassistant/components/flick_electric/sensor.py @@ -8,12 +8,7 @@ from pyflick import FlickAPI, FlickPrice from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ( - ATTR_ATTRIBUTION, - ATTR_FRIENDLY_NAME, - CURRENCY_CENT, - ENERGY_KILO_WATT_HOUR, -) +from homeassistant.const import ATTR_FRIENDLY_NAME, CURRENCY_CENT, ENERGY_KILO_WATT_HOUR from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.util.dt import utcnow @@ -24,7 +19,6 @@ _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(minutes=5) -ATTRIBUTION = "Data provided by Flick Electric" FRIENDLY_NAME = "Flick Power Price" @@ -40,6 +34,7 @@ async def async_setup_entry( class FlickPricingSensor(SensorEntity): """Entity object for Flick Electric sensor.""" + _attr_attribution = "Data provided by Flick Electric" _attr_native_unit_of_measurement = f"{CURRENCY_CENT}/{ENERGY_KILO_WATT_HOUR}" def __init__(self, api: FlickAPI) -> None: @@ -47,7 +42,6 @@ class FlickPricingSensor(SensorEntity): self._api: FlickAPI = api self._price: FlickPrice = None self._attributes: dict[str, Any] = { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_FRIENDLY_NAME: FRIENDLY_NAME, } diff --git a/homeassistant/components/geonetnz_volcano/sensor.py b/homeassistant/components/geonetnz_volcano/sensor.py index e48a4cec0cf..e78641f99e2 100644 --- a/homeassistant/components/geonetnz_volcano/sensor.py +++ b/homeassistant/components/geonetnz_volcano/sensor.py @@ -6,7 +6,6 @@ import logging from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, ATTR_LATITUDE, ATTR_LONGITUDE, LENGTH_KILOMETERS, @@ -124,7 +123,7 @@ class GeonetnzVolcanoSensor(SensorEntity): self._distance = round(feed_entry.distance_to_home, 1) self._latitude = round(feed_entry.coordinates[0], 5) self._longitude = round(feed_entry.coordinates[1], 5) - self._attribution = feed_entry.attribution + self._attr_attribution = feed_entry.attribution self._alert_level = feed_entry.alert_level self._activity = feed_entry.activity self._hazards = feed_entry.hazards @@ -159,7 +158,6 @@ class GeonetnzVolcanoSensor(SensorEntity): attributes = {} for key, value in ( (ATTR_EXTERNAL_ID, self._external_id), - (ATTR_ATTRIBUTION, self._attribution), (ATTR_ACTIVITY, self._activity), (ATTR_HAZARDS, self._hazards), (ATTR_LONGITUDE, self._longitude), diff --git a/homeassistant/components/gios/sensor.py b/homeassistant/components/gios/sensor.py index 2d32b8261f3..aa528f3d1d3 100644 --- a/homeassistant/components/gios/sensor.py +++ b/homeassistant/components/gios/sensor.py @@ -15,7 +15,6 @@ from homeassistant.components.sensor import ( ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, ATTR_NAME, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, CONF_NAME, @@ -154,6 +153,7 @@ async def async_setup_entry( class GiosSensor(CoordinatorEntity[GiosDataUpdateCoordinator], SensorEntity): """Define an GIOS sensor.""" + _attr_attribution = ATTRIBUTION _attr_has_entity_name = True entity_description: GiosSensorEntityDescription @@ -174,7 +174,6 @@ class GiosSensor(CoordinatorEntity[GiosDataUpdateCoordinator], SensorEntity): ) self._attr_unique_id = f"{coordinator.gios.station_id}-{description.key}" self._attrs: dict[str, Any] = { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_STATION: self.coordinator.gios.station_name, } self.entity_description = description diff --git a/homeassistant/components/google_travel_time/sensor.py b/homeassistant/components/google_travel_time/sensor.py index 524fae4a128..3ea38af1f27 100644 --- a/homeassistant/components/google_travel_time/sensor.py +++ b/homeassistant/components/google_travel_time/sensor.py @@ -10,7 +10,6 @@ from googlemaps.distance_matrix import distance_matrix from homeassistant.components.sensor import SensorEntity from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, CONF_API_KEY, CONF_MODE, CONF_NAME, @@ -104,6 +103,8 @@ async def async_setup_entry( class GoogleTravelTimeSensor(SensorEntity): """Representation of a Google travel time sensor.""" + _attr_attribution = ATTRIBUTION + def __init__(self, config_entry, name, api_key, origin, destination, client): """Initialize the sensor.""" self._name = name @@ -178,7 +179,6 @@ class GoogleTravelTimeSensor(SensorEntity): res["distance"] = _data["distance"]["text"] res["origin"] = self._resolved_origin res["destination"] = self._resolved_destination - res[ATTR_ATTRIBUTION] = ATTRIBUTION return res @property diff --git a/homeassistant/components/gtfs/sensor.py b/homeassistant/components/gtfs/sensor.py index 2ea0c23f213..9b733d41502 100644 --- a/homeassistant/components/gtfs/sensor.py +++ b/homeassistant/components/gtfs/sensor.py @@ -16,7 +16,7 @@ from homeassistant.components.sensor import ( SensorDeviceClass, SensorEntity, ) -from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, CONF_OFFSET, STATE_UNKNOWN +from homeassistant.const import CONF_NAME, CONF_OFFSET, STATE_UNKNOWN from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -648,6 +648,11 @@ class GTFSDepartureSensor(SensorEntity): # Assign attributes, icon and name self.update_attributes() + if self._agency: + self._attr_attribution = self._agency.agency_name + else: + self._attr_attribution = None + if self._route: self._icon = ICONS.get(self._route.route_type, ICON) else: @@ -702,11 +707,6 @@ class GTFSDepartureSensor(SensorEntity): elif ATTR_INFO in self._attributes: del self._attributes[ATTR_INFO] - if self._agency: - self._attributes[ATTR_ATTRIBUTION] = self._agency.agency_name - elif ATTR_ATTRIBUTION in self._attributes: - del self._attributes[ATTR_ATTRIBUTION] - # Add extra metadata key = "agency_id" if self._agency and key not in self._attributes: