Move attribution to standalone attribute [m-q] (#80518)

pull/80527/head
epenet 2022-10-18 12:49:59 +02:00 committed by GitHub
parent 1fe397f7d7
commit 6b256bab22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 32 additions and 49 deletions

View File

@ -12,12 +12,7 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_API_KEY,
CONF_MONITORED_CONDITIONS,
CONF_NAME,
)
from homeassistant.const import CONF_API_KEY, CONF_MONITORED_CONDITIONS, CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -34,7 +29,6 @@ CONF_UNITS = "units"
DEFAULT_UNIT = "us"
DEFAULT_NAME = "MSW"
DEFAULT_ATTRIBUTION = "Data provided by magicseaweed.com"
ICON = "mdi:waves"
@ -127,6 +121,7 @@ def setup_platform(
class MagicSeaweedSensor(SensorEntity):
"""Implementation of a MagicSeaweed sensor."""
_attr_attribution = "Data provided by magicseaweed.com"
_attr_icon = ICON
def __init__(
@ -151,7 +146,7 @@ class MagicSeaweedSensor(SensorEntity):
else:
self._attr_name = f"{hour} {name} {description.name}"
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._attr_extra_state_attributes = {}
@property
def unit_system(self):

View File

@ -8,7 +8,6 @@ from meteofrance_api.helpers import (
from homeassistant.components.sensor import SensorEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo
@ -81,6 +80,7 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity):
"""Representation of a Meteo-France sensor."""
entity_description: MeteoFranceSensorEntityDescription
_attr_attribution = ATTRIBUTION
def __init__(
self,
@ -94,7 +94,6 @@ class MeteoFranceSensor(CoordinatorEntity, SensorEntity):
city_name = coordinator.data.position["name"]
self._attr_name = f"{city_name} {description.name}"
self._attr_unique_id = f"{coordinator.data.position['lat']},{coordinator.data.position['lon']}_{description.key}"
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
@property
def device_info(self) -> DeviceInfo:
@ -162,7 +161,6 @@ class MeteoFranceRainSensor(MeteoFranceSensor):
f"{int((item['dt'] - reference_dt) / 60)} min": item["desc"]
for item in self.coordinator.data.forecast
},
ATTR_ATTRIBUTION: ATTRIBUTION,
}
@ -192,7 +190,6 @@ class MeteoFranceAlertSensor(MeteoFranceSensor):
"""Return the state attributes."""
return {
**readeable_phenomenoms_dict(self.coordinator.data.phenomenons_max_colors),
ATTR_ATTRIBUTION: ATTRIBUTION,
}

View File

@ -12,7 +12,6 @@ from homeassistant.components.sensor import (
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
ATTR_ATTRIBUTION,
LENGTH_KILOMETERS,
PERCENTAGE,
SPEED_MILES_PER_HOUR,
@ -180,6 +179,7 @@ class MetOfficeCurrentSensor(
):
"""Implementation of a Met Office current weather condition sensor."""
_attr_attribution = ATTRIBUTION
_attr_has_entity_name = True
def __init__(
@ -258,7 +258,6 @@ class MetOfficeCurrentSensor(
def extra_state_attributes(self) -> dict[str, Any]:
"""Return the state attributes of the device."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_LAST_UPDATE: self.coordinator.data.now.date,
ATTR_SENSOR_ID: self.entity_description.key,
ATTR_SITE_ID: self.coordinator.data.site.id,

View File

@ -9,7 +9,7 @@ import MVGLive
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
@ -90,6 +90,8 @@ def setup_platform(
class MVGLiveSensor(SensorEntity):
"""Implementation of an MVG Live sensor."""
_attr_attribution = ATTRIBUTION
def __init__(
self,
station,
@ -210,7 +212,7 @@ class MVGLiveData:
continue
# now select the relevant data
_nextdep = {ATTR_ATTRIBUTION: ATTRIBUTION}
_nextdep = {}
for k in ("destination", "linename", "time", "direction", "product"):
_nextdep[k] = _departure.get(k, "")
_nextdep["time"] = int(_nextdep["time"])

View File

@ -10,7 +10,7 @@ import requests
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY, CONF_NAME
from homeassistant.const import CONF_API_KEY, CONF_NAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
@ -20,8 +20,6 @@ from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by NS"
CONF_ROUTES = "routes"
CONF_FROM = "from"
CONF_TO = "to"
@ -105,6 +103,8 @@ def valid_stations(stations, given_stations):
class NSDepartureSensor(SensorEntity):
"""Implementation of a NS Departure Sensor."""
_attr_attribution = "Data provided by NS"
def __init__(self, nsapi, name, departure, heading, via, time):
"""Initialize the sensor."""
self._nsapi = nsapi
@ -160,7 +160,6 @@ class NSDepartureSensor(SensorEntity):
"transfers": self._trips[0].nr_transfers,
"route": route,
"remarks": None,
ATTR_ATTRIBUTION: ATTRIBUTION,
}
# Planned departure attributes

View File

@ -8,7 +8,6 @@ from pyatmo.modules.device_types import (
DeviceType as NetatmoDeviceType,
)
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import callback
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.entity import DeviceInfo, Entity
@ -20,6 +19,8 @@ from .data_handler import PUBLIC, NetatmoDataHandler
class NetatmoBase(Entity):
"""Netatmo entity base class."""
_attr_attribution = DEFAULT_ATTRIBUTION
def __init__(self, data_handler: NetatmoDataHandler) -> None:
"""Set up Netatmo entity base."""
self.data_handler = data_handler
@ -31,7 +32,7 @@ class NetatmoBase(Entity):
self._config_url: str = ""
self._attr_name = None
self._attr_unique_id = None
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
self._attr_extra_state_attributes = {}
async def async_added_to_hass(self) -> None:
"""Entity created."""

View File

@ -8,7 +8,6 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_LATITUDE,
ATTR_LONGITUDE,
CONF_NAME,
@ -100,6 +99,8 @@ def setup_platform(
class NMBSLiveBoard(SensorEntity):
"""Get the next train from a station's liveboard."""
_attr_attribution = "https://api.irail.be/"
def __init__(self, api_client, live_station, station_from, station_to):
"""Initialize the sensor for getting liveboard data."""
self._station = live_station
@ -149,7 +150,6 @@ class NMBSLiveBoard(SensorEntity):
"extra_train": int(self._attrs["isExtra"]) > 0,
"vehicle_id": self._attrs["vehicle"],
"monitored_station": self._station,
ATTR_ATTRIBUTION: "https://api.irail.be/",
}
if delay > 0:
@ -176,6 +176,7 @@ class NMBSLiveBoard(SensorEntity):
class NMBSSensor(SensorEntity):
"""Get the the total travel time for a given connection."""
_attr_attribution = "https://api.irail.be/"
_attr_native_unit_of_measurement = TIME_MINUTES
def __init__(
@ -223,7 +224,6 @@ class NMBSSensor(SensorEntity):
"platform_arriving": self._attrs["arrival"]["platform"],
"platform_departing": self._attrs["departure"]["platform"],
"vehicle_id": self._attrs["departure"]["vehicle"],
ATTR_ATTRIBUTION: "https://api.irail.be/",
}
if canceled != 1:

View File

@ -9,12 +9,7 @@ import requests
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_NAME,
CONF_TIME_ZONE,
CONF_UNIT_SYSTEM,
)
from homeassistant.const import CONF_NAME, CONF_TIME_ZONE, CONF_UNIT_SYSTEM
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
import homeassistant.helpers.config_validation as cv
@ -26,7 +21,6 @@ _LOGGER = logging.getLogger(__name__)
CONF_STATION_ID = "station_id"
DEFAULT_ATTRIBUTION = "Data provided by NOAA"
DEFAULT_NAME = "NOAA Tides"
DEFAULT_TIMEZONE = "lst_ldt"
@ -85,6 +79,8 @@ def setup_platform(
class NOAATidesAndCurrentsSensor(SensorEntity):
"""Representation of a NOAA Tides and Currents sensor."""
_attr_attribution = "Data provided by NOAA"
def __init__(self, name, station_id, timezone, unit_system, station):
"""Initialize the sensor."""
self._name = name
@ -102,7 +98,7 @@ class NOAATidesAndCurrentsSensor(SensorEntity):
@property
def extra_state_attributes(self):
"""Return the state attributes of this device."""
attr = {ATTR_ATTRIBUTION: DEFAULT_ATTRIBUTION}
attr = {}
if self.data is None:
return attr
if self.data["hi_lo"][1] == "H":

View File

@ -6,7 +6,7 @@ import logging
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import ATTR_ATTRIBUTION, CURRENCY_CENT, VOLUME_LITERS
from homeassistant.const import CURRENCY_CENT, VOLUME_LITERS
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -40,7 +40,6 @@ CONF_ALLOWED_FUEL_TYPES = [
]
CONF_DEFAULT_FUEL_TYPES = ["E10", "U91"]
ATTRIBUTION = "Data provided by NSW Government FuelCheck"
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_STATION_ID): cv.positive_int,
@ -88,6 +87,8 @@ class StationPriceSensor(
):
"""Implementation of a sensor that reports the fuel price for a station."""
_attr_attribution = "Data provided by NSW Government FuelCheck"
def __init__(
self,
coordinator: DataUpdateCoordinator[StationPriceData],
@ -121,7 +122,6 @@ class StationPriceSensor(
return {
ATTR_STATION_ID: self._station_id,
ATTR_STATION_NAME: self._get_station_name(),
ATTR_ATTRIBUTION: ATTRIBUTION,
}
@property

View File

@ -13,7 +13,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
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -30,8 +30,6 @@ ATTR_NEXT_ARRIVAL = "next_arrival"
ATTR_SECOND_NEXT_ARRIVAL = "second_next_arrival"
ATTR_NEXT_DEPARTURE = "next_departure"
ATTRIBUTION = "Data retrieved from telematics.oasa.gr"
CONF_STOP_ID = "stop_id"
CONF_ROUTE_ID = "route_id"
@ -68,6 +66,8 @@ def setup_platform(
class OASATelematicsSensor(SensorEntity):
"""Implementation of the OASA Telematics sensor."""
_attr_attribution = "Data retrieved from telematics.oasa.gr"
def __init__(self, data, stop_id, route_id, name):
"""Initialize the sensor."""
self.data = data
@ -111,7 +111,6 @@ class OASATelematicsSensor(SensorEntity):
{
ATTR_ROUTE_ID: self._times[0][ATTR_ROUTE_ID],
ATTR_STOP_ID: self._stop_id,
ATTR_ATTRIBUTION: ATTRIBUTION,
}
)
params.update(

View File

@ -8,7 +8,6 @@ import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
from homeassistant.const import (
ATTR_ATTRIBUTION,
ATTR_LATITUDE,
ATTR_LONGITUDE,
CONF_LATITUDE,
@ -42,9 +41,6 @@ EVENT_OPENSKY_ENTRY = f"{DOMAIN}_entry"
EVENT_OPENSKY_EXIT = f"{DOMAIN}_exit"
SCAN_INTERVAL = timedelta(seconds=12) # opensky public limit is 10 seconds
OPENSKY_ATTRIBUTION = (
"Information provided by the OpenSky Network (https://opensky-network.org)"
)
OPENSKY_API_URL = "https://opensky-network.org/api/states/all"
OPENSKY_API_FIELDS = [
ATTR_ICAO24,
@ -101,6 +97,10 @@ def setup_platform(
class OpenSkySensor(SensorEntity):
"""Open Sky Network Sensor."""
_attr_attribution = (
"Information provided by the OpenSky Network (https://opensky-network.org)"
)
def __init__(self, hass, name, latitude, longitude, radius, altitude):
"""Initialize the sensor."""
self._session = requests.Session()
@ -188,11 +188,6 @@ class OpenSkySensor(SensorEntity):
self._state = len(currently_tracked)
self._previously_tracked = currently_tracked
@property
def extra_state_attributes(self):
"""Return the state attributes."""
return {ATTR_ATTRIBUTION: OPENSKY_ATTRIBUTION}
@property
def native_unit_of_measurement(self):
"""Return the unit of measurement."""