Move attribution to standalone attribute [c-d] (#80150)

This commit is contained in:
epenet 2022-10-12 11:38:43 +02:00 committed by GitHub
parent 237b03150e
commit e9e3fb1cc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 20 additions and 45 deletions

View file

@ -15,7 +15,7 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME, CONF_OFFSET
from homeassistant.const import CONF_NAME, CONF_OFFSET
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import async_get_clientsession
import homeassistant.helpers.config_validation as cv
@ -27,8 +27,6 @@ _RESOURCE = "https://hourlypricing.comed.com/api"
SCAN_INTERVAL = timedelta(minutes=5)
ATTRIBUTION = "Data provided by ComEd Hourly Pricing service"
CONF_CURRENT_HOUR_AVERAGE = "current_hour_average"
CONF_FIVE_MINUTE = "five_minute"
CONF_MONITORED_FEEDS = "monitored_feeds"
@ -91,7 +89,7 @@ async def async_setup_platform(
class ComedHourlyPricingSensor(SensorEntity):
"""Implementation of a ComEd Hourly Pricing sensor."""
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
_attr_attribution = "Data provided by ComEd Hourly Pricing service"
def __init__(self, websession, offset, name, description: SensorEntityDescription):
"""Initialize the sensor."""

View file

@ -1,7 +1,6 @@
"""Sensor platform for the Corona virus."""
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.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
@ -34,12 +33,12 @@ async def async_setup_entry(
class CoronavirusSensor(CoordinatorEntity, SensorEntity):
"""Sensor representing corona virus data."""
_attr_attribution = ATTRIBUTION
_attr_native_unit_of_measurement = "people"
def __init__(self, coordinator, country, info_type):
"""Initialize coronavirus sensor."""
super().__init__(coordinator)
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
self._attr_icon = SENSORS[info_type]
self._attr_unique_id = f"{country}-{info_type}"
if country == OPTION_WORLDWIDE:

View file

@ -8,13 +8,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_BASE,
CONF_NAME,
CONF_QUOTE,
)
from homeassistant.const import CONF_API_KEY, CONF_BASE, CONF_NAME, CONF_QUOTE
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -23,8 +17,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
_LOGGER = logging.getLogger(__name__)
_RESOURCE = "http://apilayer.net/api/live"
ATTRIBUTION = "Data provided by currencylayer.com"
DEFAULT_BASE = "USD"
DEFAULT_NAME = "CurrencyLayer Sensor"
@ -67,6 +59,8 @@ def setup_platform(
class CurrencylayerSensor(SensorEntity):
"""Implementing the Currencylayer sensor."""
_attr_attribution = "Data provided by currencylayer.com"
def __init__(self, rest, base, quote):
"""Initialize the sensor."""
self.rest = rest
@ -94,11 +88,6 @@ class CurrencylayerSensor(SensorEntity):
"""Return the state of the sensor."""
return self._state
@property
def extra_state_attributes(self):
"""Return the state attributes of the sensor."""
return {ATTR_ATTRIBUTION: ATTRIBUTION}
def update(self) -> None:
"""Update current date."""
self.rest.update()

View file

@ -18,7 +18,6 @@ from homeassistant.components.sensor import (
SensorStateClass,
)
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_API_KEY,
CONF_LATITUDE,
CONF_LONGITUDE,
@ -49,8 +48,6 @@ from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Powered by Dark Sky"
CONF_FORECAST = "forecast"
CONF_HOURLY_FORECAST = "hourly_forecast"
CONF_LANGUAGE = "language"
@ -647,8 +644,8 @@ def setup_platform(
class DarkSkySensor(SensorEntity):
"""Implementation of a Dark Sky sensor."""
_attr_attribution = "Powered by Dark Sky"
entity_description: DarkskySensorEntityDescription
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
def __init__(
self,

View file

@ -10,7 +10,6 @@ from homeassistant.components.binary_sensor import (
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -64,6 +63,8 @@ def setup_platform(
class DigitalOceanBinarySensor(BinarySensorEntity):
"""Representation of a Digital Ocean droplet sensor."""
_attr_attribution = ATTRIBUTION
def __init__(self, do, droplet_id): # pylint: disable=invalid-name
"""Initialize a new Digital Ocean sensor."""
self._digital_ocean = do
@ -90,7 +91,6 @@ class DigitalOceanBinarySensor(BinarySensorEntity):
def extra_state_attributes(self):
"""Return the state attributes of the Digital Ocean droplet."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_CREATED_AT: self.data.created_at,
ATTR_DROPLET_ID: self.data.id,
ATTR_DROPLET_NAME: self.data.name,

View file

@ -7,7 +7,6 @@ from typing import Any
import voluptuous as vol
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
from homeassistant.const import ATTR_ATTRIBUTION
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -62,6 +61,8 @@ def setup_platform(
class DigitalOceanSwitch(SwitchEntity):
"""Representation of a Digital Ocean droplet switch."""
_attr_attribution = ATTRIBUTION
def __init__(self, do, droplet_id): # pylint: disable=invalid-name
"""Initialize a new Digital Ocean sensor."""
self._digital_ocean = do
@ -83,7 +84,6 @@ class DigitalOceanSwitch(SwitchEntity):
def extra_state_attributes(self):
"""Return the state attributes of the Digital Ocean droplet."""
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_CREATED_AT: self.data.created_at,
ATTR_DROPLET_ID: self.data.id,
ATTR_DROPLET_NAME: self.data.name,

View file

@ -13,12 +13,7 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_MONITORED_CONDITIONS,
CONF_NAME,
CONF_TOKEN,
)
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_TOKEN
from homeassistant.core import HomeAssistant
from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE
import homeassistant.helpers.config_validation as cv
@ -29,8 +24,6 @@ _LOGGER = logging.getLogger(__name__)
ATTR_IDENTITY = "identity"
ATTRIBUTION = "Data provided by Discogs"
DEFAULT_NAME = "Discogs"
ICON_RECORD = "mdi:album"
@ -111,6 +104,8 @@ def setup_platform(
class DiscogsSensor(SensorEntity):
"""Create a new Discogs sensor for a specific type."""
_attr_attribution = "Data provided by Discogs"
def __init__(self, discogs_data, name, description: SensorEntityDescription):
"""Initialize the Discogs sensor."""
self.entity_description = description
@ -135,12 +130,10 @@ class DiscogsSensor(SensorEntity):
"format": f"{self._attrs['formats'][0]['name']} ({self._attrs['formats'][0]['descriptions'][0]})",
"label": self._attrs["labels"][0]["name"],
"released": self._attrs["year"],
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_IDENTITY: self._discogs_data["user"],
}
return {
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_IDENTITY: self._discogs_data["user"],
}

View file

@ -14,7 +14,7 @@ import requests
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
@ -29,8 +29,6 @@ ATTR_DUE_IN = "Due in"
ATTR_DUE_AT = "Due at"
ATTR_NEXT_UP = "Later Bus"
ATTRIBUTION = "Data provided by data.dublinked.ie"
CONF_STOP_ID = "stopid"
CONF_ROUTE = "route"
@ -79,6 +77,8 @@ def setup_platform(
class DublinPublicTransportSensor(SensorEntity):
"""Implementation of an Dublin public transport sensor."""
_attr_attribution = "Data provided by data.dublinked.ie"
def __init__(self, data, stop, route, name):
"""Initialize the sensor."""
self.data = data
@ -111,7 +111,6 @@ class DublinPublicTransportSensor(SensorEntity):
ATTR_DUE_AT: self._times[0][ATTR_DUE_AT],
ATTR_STOP_ID: self._stop,
ATTR_ROUTE: self._times[0][ATTR_ROUTE],
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_NEXT_UP: next_up,
}

View file

@ -22,7 +22,7 @@ from homeassistant.components.sensor import (
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS, CONF_NAME
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -31,7 +31,6 @@ from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Data provided by DWD"
ATTR_REGION_NAME = "region_name"
ATTR_REGION_ID = "region_id"
ATTR_LAST_UPDATE = "last_update"
@ -108,6 +107,8 @@ def setup_platform(
class DwdWeatherWarningsSensor(SensorEntity):
"""Representation of a DWD-Weather-Warnings sensor."""
_attr_attribution = "Data provided by DWD"
def __init__(
self,
api,
@ -130,7 +131,6 @@ class DwdWeatherWarningsSensor(SensorEntity):
def extra_state_attributes(self):
"""Return the state attributes of the DWD-Weather-Warnings."""
data = {
ATTR_ATTRIBUTION: ATTRIBUTION,
ATTR_REGION_NAME: self._api.api.warncell_name,
ATTR_REGION_ID: self._api.api.warncell_id,
ATTR_LAST_UPDATE: self._api.api.last_update,