Move attribution to standalone attribute [c-d] (#80150)
This commit is contained in:
parent
237b03150e
commit
e9e3fb1cc8
9 changed files with 20 additions and 45 deletions
|
@ -15,7 +15,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -27,8 +27,6 @@ _RESOURCE = "https://hourlypricing.comed.com/api"
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(minutes=5)
|
SCAN_INTERVAL = timedelta(minutes=5)
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by ComEd Hourly Pricing service"
|
|
||||||
|
|
||||||
CONF_CURRENT_HOUR_AVERAGE = "current_hour_average"
|
CONF_CURRENT_HOUR_AVERAGE = "current_hour_average"
|
||||||
CONF_FIVE_MINUTE = "five_minute"
|
CONF_FIVE_MINUTE = "five_minute"
|
||||||
CONF_MONITORED_FEEDS = "monitored_feeds"
|
CONF_MONITORED_FEEDS = "monitored_feeds"
|
||||||
|
@ -91,7 +89,7 @@ async def async_setup_platform(
|
||||||
class ComedHourlyPricingSensor(SensorEntity):
|
class ComedHourlyPricingSensor(SensorEntity):
|
||||||
"""Implementation of a ComEd Hourly Pricing sensor."""
|
"""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):
|
def __init__(self, websession, offset, name, description: SensorEntityDescription):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Sensor platform for the Corona virus."""
|
"""Sensor platform for the Corona virus."""
|
||||||
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 ATTR_ATTRIBUTION
|
|
||||||
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.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
@ -34,12 +33,12 @@ async def async_setup_entry(
|
||||||
class CoronavirusSensor(CoordinatorEntity, SensorEntity):
|
class CoronavirusSensor(CoordinatorEntity, SensorEntity):
|
||||||
"""Sensor representing corona virus data."""
|
"""Sensor representing corona virus data."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
_attr_native_unit_of_measurement = "people"
|
_attr_native_unit_of_measurement = "people"
|
||||||
|
|
||||||
def __init__(self, coordinator, country, info_type):
|
def __init__(self, coordinator, country, info_type):
|
||||||
"""Initialize coronavirus sensor."""
|
"""Initialize coronavirus sensor."""
|
||||||
super().__init__(coordinator)
|
super().__init__(coordinator)
|
||||||
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
|
||||||
self._attr_icon = SENSORS[info_type]
|
self._attr_icon = SENSORS[info_type]
|
||||||
self._attr_unique_id = f"{country}-{info_type}"
|
self._attr_unique_id = f"{country}-{info_type}"
|
||||||
if country == OPTION_WORLDWIDE:
|
if country == OPTION_WORLDWIDE:
|
||||||
|
|
|
@ -8,13 +8,7 @@ import requests
|
||||||
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 (
|
from homeassistant.const import CONF_API_KEY, CONF_BASE, CONF_NAME, CONF_QUOTE
|
||||||
ATTR_ATTRIBUTION,
|
|
||||||
CONF_API_KEY,
|
|
||||||
CONF_BASE,
|
|
||||||
CONF_NAME,
|
|
||||||
CONF_QUOTE,
|
|
||||||
)
|
|
||||||
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
|
||||||
|
@ -23,8 +17,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
_RESOURCE = "http://apilayer.net/api/live"
|
_RESOURCE = "http://apilayer.net/api/live"
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by currencylayer.com"
|
|
||||||
|
|
||||||
DEFAULT_BASE = "USD"
|
DEFAULT_BASE = "USD"
|
||||||
DEFAULT_NAME = "CurrencyLayer Sensor"
|
DEFAULT_NAME = "CurrencyLayer Sensor"
|
||||||
|
|
||||||
|
@ -67,6 +59,8 @@ def setup_platform(
|
||||||
class CurrencylayerSensor(SensorEntity):
|
class CurrencylayerSensor(SensorEntity):
|
||||||
"""Implementing the Currencylayer sensor."""
|
"""Implementing the Currencylayer sensor."""
|
||||||
|
|
||||||
|
_attr_attribution = "Data provided by currencylayer.com"
|
||||||
|
|
||||||
def __init__(self, rest, base, quote):
|
def __init__(self, rest, base, quote):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.rest = rest
|
self.rest = rest
|
||||||
|
@ -94,11 +88,6 @@ class CurrencylayerSensor(SensorEntity):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
@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:
|
||||||
"""Update current date."""
|
"""Update current date."""
|
||||||
self.rest.update()
|
self.rest.update()
|
||||||
|
|
|
@ -18,7 +18,6 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ATTRIBUTION,
|
|
||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
|
@ -49,8 +48,6 @@ from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTRIBUTION = "Powered by Dark Sky"
|
|
||||||
|
|
||||||
CONF_FORECAST = "forecast"
|
CONF_FORECAST = "forecast"
|
||||||
CONF_HOURLY_FORECAST = "hourly_forecast"
|
CONF_HOURLY_FORECAST = "hourly_forecast"
|
||||||
CONF_LANGUAGE = "language"
|
CONF_LANGUAGE = "language"
|
||||||
|
@ -647,8 +644,8 @@ def setup_platform(
|
||||||
class DarkSkySensor(SensorEntity):
|
class DarkSkySensor(SensorEntity):
|
||||||
"""Implementation of a Dark Sky sensor."""
|
"""Implementation of a Dark Sky sensor."""
|
||||||
|
|
||||||
|
_attr_attribution = "Powered by Dark Sky"
|
||||||
entity_description: DarkskySensorEntityDescription
|
entity_description: DarkskySensorEntityDescription
|
||||||
_attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -10,7 +10,6 @@ from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION
|
|
||||||
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
|
||||||
|
@ -64,6 +63,8 @@ def setup_platform(
|
||||||
class DigitalOceanBinarySensor(BinarySensorEntity):
|
class DigitalOceanBinarySensor(BinarySensorEntity):
|
||||||
"""Representation of a Digital Ocean droplet sensor."""
|
"""Representation of a Digital Ocean droplet sensor."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
|
||||||
def __init__(self, do, droplet_id): # pylint: disable=invalid-name
|
def __init__(self, do, droplet_id): # pylint: disable=invalid-name
|
||||||
"""Initialize a new Digital Ocean sensor."""
|
"""Initialize a new Digital Ocean sensor."""
|
||||||
self._digital_ocean = do
|
self._digital_ocean = do
|
||||||
|
@ -90,7 +91,6 @@ class DigitalOceanBinarySensor(BinarySensorEntity):
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes of the Digital Ocean droplet."""
|
"""Return the state attributes of the Digital Ocean droplet."""
|
||||||
return {
|
return {
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
|
||||||
ATTR_CREATED_AT: self.data.created_at,
|
ATTR_CREATED_AT: self.data.created_at,
|
||||||
ATTR_DROPLET_ID: self.data.id,
|
ATTR_DROPLET_ID: self.data.id,
|
||||||
ATTR_DROPLET_NAME: self.data.name,
|
ATTR_DROPLET_NAME: self.data.name,
|
||||||
|
|
|
@ -7,7 +7,6 @@ from typing import Any
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
||||||
from homeassistant.const import ATTR_ATTRIBUTION
|
|
||||||
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
|
||||||
|
@ -62,6 +61,8 @@ def setup_platform(
|
||||||
class DigitalOceanSwitch(SwitchEntity):
|
class DigitalOceanSwitch(SwitchEntity):
|
||||||
"""Representation of a Digital Ocean droplet switch."""
|
"""Representation of a Digital Ocean droplet switch."""
|
||||||
|
|
||||||
|
_attr_attribution = ATTRIBUTION
|
||||||
|
|
||||||
def __init__(self, do, droplet_id): # pylint: disable=invalid-name
|
def __init__(self, do, droplet_id): # pylint: disable=invalid-name
|
||||||
"""Initialize a new Digital Ocean sensor."""
|
"""Initialize a new Digital Ocean sensor."""
|
||||||
self._digital_ocean = do
|
self._digital_ocean = do
|
||||||
|
@ -83,7 +84,6 @@ class DigitalOceanSwitch(SwitchEntity):
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes of the Digital Ocean droplet."""
|
"""Return the state attributes of the Digital Ocean droplet."""
|
||||||
return {
|
return {
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
|
||||||
ATTR_CREATED_AT: self.data.created_at,
|
ATTR_CREATED_AT: self.data.created_at,
|
||||||
ATTR_DROPLET_ID: self.data.id,
|
ATTR_DROPLET_ID: self.data.id,
|
||||||
ATTR_DROPLET_NAME: self.data.name,
|
ATTR_DROPLET_NAME: self.data.name,
|
||||||
|
|
|
@ -13,12 +13,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import CONF_MONITORED_CONDITIONS, CONF_NAME, CONF_TOKEN
|
||||||
ATTR_ATTRIBUTION,
|
|
||||||
CONF_MONITORED_CONDITIONS,
|
|
||||||
CONF_NAME,
|
|
||||||
CONF_TOKEN,
|
|
||||||
)
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE
|
from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -29,8 +24,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTR_IDENTITY = "identity"
|
ATTR_IDENTITY = "identity"
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by Discogs"
|
|
||||||
|
|
||||||
DEFAULT_NAME = "Discogs"
|
DEFAULT_NAME = "Discogs"
|
||||||
|
|
||||||
ICON_RECORD = "mdi:album"
|
ICON_RECORD = "mdi:album"
|
||||||
|
@ -111,6 +104,8 @@ def setup_platform(
|
||||||
class DiscogsSensor(SensorEntity):
|
class DiscogsSensor(SensorEntity):
|
||||||
"""Create a new Discogs sensor for a specific type."""
|
"""Create a new Discogs sensor for a specific type."""
|
||||||
|
|
||||||
|
_attr_attribution = "Data provided by Discogs"
|
||||||
|
|
||||||
def __init__(self, discogs_data, name, description: SensorEntityDescription):
|
def __init__(self, discogs_data, name, description: SensorEntityDescription):
|
||||||
"""Initialize the Discogs sensor."""
|
"""Initialize the Discogs sensor."""
|
||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
|
@ -135,12 +130,10 @@ class DiscogsSensor(SensorEntity):
|
||||||
"format": f"{self._attrs['formats'][0]['name']} ({self._attrs['formats'][0]['descriptions'][0]})",
|
"format": f"{self._attrs['formats'][0]['name']} ({self._attrs['formats'][0]['descriptions'][0]})",
|
||||||
"label": self._attrs["labels"][0]["name"],
|
"label": self._attrs["labels"][0]["name"],
|
||||||
"released": self._attrs["year"],
|
"released": self._attrs["year"],
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
|
||||||
ATTR_IDENTITY: self._discogs_data["user"],
|
ATTR_IDENTITY: self._discogs_data["user"],
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
|
||||||
ATTR_IDENTITY: self._discogs_data["user"],
|
ATTR_IDENTITY: self._discogs_data["user"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import requests
|
||||||
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_NAME, TIME_MINUTES
|
from homeassistant.const import CONF_NAME, TIME_MINUTES
|
||||||
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
|
||||||
|
@ -29,8 +29,6 @@ ATTR_DUE_IN = "Due in"
|
||||||
ATTR_DUE_AT = "Due at"
|
ATTR_DUE_AT = "Due at"
|
||||||
ATTR_NEXT_UP = "Later Bus"
|
ATTR_NEXT_UP = "Later Bus"
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by data.dublinked.ie"
|
|
||||||
|
|
||||||
CONF_STOP_ID = "stopid"
|
CONF_STOP_ID = "stopid"
|
||||||
CONF_ROUTE = "route"
|
CONF_ROUTE = "route"
|
||||||
|
|
||||||
|
@ -79,6 +77,8 @@ def setup_platform(
|
||||||
class DublinPublicTransportSensor(SensorEntity):
|
class DublinPublicTransportSensor(SensorEntity):
|
||||||
"""Implementation of an Dublin public transport sensor."""
|
"""Implementation of an Dublin public transport sensor."""
|
||||||
|
|
||||||
|
_attr_attribution = "Data provided by data.dublinked.ie"
|
||||||
|
|
||||||
def __init__(self, data, stop, route, name):
|
def __init__(self, data, stop, route, name):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.data = data
|
self.data = data
|
||||||
|
@ -111,7 +111,6 @@ class DublinPublicTransportSensor(SensorEntity):
|
||||||
ATTR_DUE_AT: self._times[0][ATTR_DUE_AT],
|
ATTR_DUE_AT: self._times[0][ATTR_DUE_AT],
|
||||||
ATTR_STOP_ID: self._stop,
|
ATTR_STOP_ID: self._stop,
|
||||||
ATTR_ROUTE: self._times[0][ATTR_ROUTE],
|
ATTR_ROUTE: self._times[0][ATTR_ROUTE],
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
|
||||||
ATTR_NEXT_UP: next_up,
|
ATTR_NEXT_UP: next_up,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
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
|
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
|
||||||
|
@ -31,7 +31,6 @@ from homeassistant.util import Throttle
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ATTRIBUTION = "Data provided by DWD"
|
|
||||||
ATTR_REGION_NAME = "region_name"
|
ATTR_REGION_NAME = "region_name"
|
||||||
ATTR_REGION_ID = "region_id"
|
ATTR_REGION_ID = "region_id"
|
||||||
ATTR_LAST_UPDATE = "last_update"
|
ATTR_LAST_UPDATE = "last_update"
|
||||||
|
@ -108,6 +107,8 @@ def setup_platform(
|
||||||
class DwdWeatherWarningsSensor(SensorEntity):
|
class DwdWeatherWarningsSensor(SensorEntity):
|
||||||
"""Representation of a DWD-Weather-Warnings sensor."""
|
"""Representation of a DWD-Weather-Warnings sensor."""
|
||||||
|
|
||||||
|
_attr_attribution = "Data provided by DWD"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
api,
|
api,
|
||||||
|
@ -130,7 +131,6 @@ class DwdWeatherWarningsSensor(SensorEntity):
|
||||||
def extra_state_attributes(self):
|
def extra_state_attributes(self):
|
||||||
"""Return the state attributes of the DWD-Weather-Warnings."""
|
"""Return the state attributes of the DWD-Weather-Warnings."""
|
||||||
data = {
|
data = {
|
||||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
|
||||||
ATTR_REGION_NAME: self._api.api.warncell_name,
|
ATTR_REGION_NAME: self._api.api.warncell_name,
|
||||||
ATTR_REGION_ID: self._api.api.warncell_id,
|
ATTR_REGION_ID: self._api.api.warncell_id,
|
||||||
ATTR_LAST_UPDATE: self._api.api.last_update,
|
ATTR_LAST_UPDATE: self._api.api.last_update,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue