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