From 5d207f77aeb9e138ba6f81a5f04c6d0d1cb0d178 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Tue, 18 Oct 2022 11:18:22 +0200 Subject: [PATCH] Move attribution to standalone attribute [h-l] (#80516) --- homeassistant/components/haveibeenpwned/sensor.py | 8 ++++---- homeassistant/components/hvv_departures/binary_sensor.py | 4 ++-- homeassistant/components/hydrawise/__init__.py | 8 ++++---- homeassistant/components/icloud/account.py | 7 +++---- homeassistant/components/iperf3/sensor.py | 6 ++---- homeassistant/components/irish_rail_transport/sensor.py | 6 +++--- homeassistant/components/lastfm/sensor.py | 6 +++--- homeassistant/components/logi_circle/camera.py | 3 +-- homeassistant/components/logi_circle/sensor.py | 4 ++-- homeassistant/components/london_underground/sensor.py | 9 +++------ 10 files changed, 27 insertions(+), 34 deletions(-) diff --git a/homeassistant/components/haveibeenpwned/sensor.py b/homeassistant/components/haveibeenpwned/sensor.py index 400c280263a..199035b2713 100644 --- a/homeassistant/components/haveibeenpwned/sensor.py +++ b/homeassistant/components/haveibeenpwned/sensor.py @@ -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_EMAIL +from homeassistant.const import CONF_API_KEY, CONF_EMAIL from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -21,8 +21,6 @@ import homeassistant.util.dt as dt_util _LOGGER = logging.getLogger(__name__) -ATTRIBUTION = "Data provided by Have I Been Pwned (HIBP)" - DATE_STR_FORMAT = "%Y-%m-%d %H:%M:%S" HA_USER_AGENT = "Home Assistant HaveIBeenPwned Sensor Component" @@ -61,6 +59,8 @@ def setup_platform( class HaveIBeenPwnedSensor(SensorEntity): """Implementation of a HaveIBeenPwned sensor.""" + _attr_attribution = "Data provided by Have I Been Pwned (HIBP)" + def __init__(self, data, email): """Initialize the HaveIBeenPwned sensor.""" self._state = None @@ -86,7 +86,7 @@ class HaveIBeenPwnedSensor(SensorEntity): @property def extra_state_attributes(self): """Return the attributes of the sensor.""" - val = {ATTR_ATTRIBUTION: ATTRIBUTION} + val = {} if self._email not in self._data.data: return val diff --git a/homeassistant/components/hvv_departures/binary_sensor.py b/homeassistant/components/hvv_departures/binary_sensor.py index 6a2f1467b19..106279cbb91 100644 --- a/homeassistant/components/hvv_departures/binary_sensor.py +++ b/homeassistant/components/hvv_departures/binary_sensor.py @@ -14,7 +14,6 @@ from homeassistant.components.binary_sensor import ( BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -78,7 +77,6 @@ async def async_setup_entry( "button_type": elevator.get("buttonType"), "cause": elevator.get("cause"), "lines": lines, - ATTR_ATTRIBUTION: ATTRIBUTION, }, } return elevators @@ -126,6 +124,8 @@ async def async_setup_entry( class HvvDepartureBinarySensor(CoordinatorEntity, BinarySensorEntity): """HVVDepartureBinarySensor class.""" + _attr_attribution = ATTRIBUTION + def __init__(self, coordinator, idx, config_entry): """Initialize.""" super().__init__(coordinator) diff --git a/homeassistant/components/hydrawise/__init__.py b/homeassistant/components/hydrawise/__init__.py index d92d785fadf..da413cce5ab 100644 --- a/homeassistant/components/hydrawise/__init__.py +++ b/homeassistant/components/hydrawise/__init__.py @@ -7,7 +7,7 @@ from requests.exceptions import ConnectTimeout, HTTPError import voluptuous as vol from homeassistant.components import persistent_notification -from homeassistant.const import ATTR_ATTRIBUTION, CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL +from homeassistant.const import CONF_ACCESS_TOKEN, CONF_SCAN_INTERVAL from homeassistant.core import HomeAssistant, callback import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send @@ -19,8 +19,6 @@ _LOGGER = logging.getLogger(__name__) ALLOWED_WATERING_TIME = [5, 10, 15, 30, 45, 60] -ATTRIBUTION = "Data provided by hydrawise.com" - CONF_WATERING_TIME = "watering_minutes" NOTIFICATION_ID = "hydrawise_notification" @@ -89,6 +87,8 @@ class HydrawiseHub: class HydrawiseEntity(Entity): """Entity class for Hydrawise devices.""" + _attr_attribution = "Data provided by hydrawise.com" + def __init__(self, data, description: EntityDescription): """Initialize the Hydrawise entity.""" self.entity_description = description @@ -111,4 +111,4 @@ class HydrawiseEntity(Entity): @property def extra_state_attributes(self): """Return the state attributes.""" - return {ATTR_ATTRIBUTION: ATTRIBUTION, "identifier": self.data.get("relay")} + return {"identifier": self.data.get("relay")} diff --git a/homeassistant/components/icloud/account.py b/homeassistant/components/icloud/account.py index c51f6a3ac26..7dc0e0ec830 100644 --- a/homeassistant/components/icloud/account.py +++ b/homeassistant/components/icloud/account.py @@ -16,7 +16,7 @@ from pyicloud.services.findmyiphone import AppleDevice from homeassistant.components.zone import async_active_zone from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_ATTRIBUTION, CONF_USERNAME +from homeassistant.const import CONF_USERNAME from homeassistant.core import CALLBACK_TYPE, HomeAssistant from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers.dispatcher import dispatcher_send @@ -48,8 +48,6 @@ from .const import ( DOMAIN, ) -ATTRIBUTION = "Data provided by Apple iCloud" - # entity attributes ATTR_ACCOUNT_FETCH_INTERVAL = "account_fetch_interval" ATTR_BATTERY = "battery" @@ -368,6 +366,8 @@ class IcloudAccount: class IcloudDevice: """Representation of a iCloud device.""" + _attr_attribution = "Data provided by Apple iCloud" + def __init__(self, account: IcloudAccount, device: AppleDevice, status) -> None: """Initialize the iCloud device.""" self._account = account @@ -385,7 +385,6 @@ class IcloudDevice: self._location = None self._attrs = { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_ACCOUNT_FETCH_INTERVAL: self._account.fetch_interval, ATTR_DEVICE_NAME: self._device_model, ATTR_DEVICE_STATUS: None, diff --git a/homeassistant/components/iperf3/sensor.py b/homeassistant/components/iperf3/sensor.py index 2dffabeeb8c..3d13c302606 100644 --- a/homeassistant/components/iperf3/sensor.py +++ b/homeassistant/components/iperf3/sensor.py @@ -2,7 +2,7 @@ from __future__ import annotations from homeassistant.components.sensor import SensorEntity, SensorEntityDescription -from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS +from homeassistant.const import CONF_MONITORED_CONDITIONS from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -11,8 +11,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType from . import ATTR_VERSION, DATA_UPDATED, DOMAIN as IPERF3_DOMAIN, SENSOR_TYPES -ATTRIBUTION = "Data retrieved using Iperf3" - ICON = "mdi:speedometer" ATTR_PROTOCOL = "Protocol" @@ -42,6 +40,7 @@ async def async_setup_platform( class Iperf3Sensor(RestoreEntity, SensorEntity): """A Iperf3 sensor implementation.""" + _attr_attribution = "Data retrieved using Iperf3" _attr_icon = ICON _attr_should_poll = False @@ -55,7 +54,6 @@ class Iperf3Sensor(RestoreEntity, SensorEntity): def extra_state_attributes(self): """Return the state attributes.""" return { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_PROTOCOL: self._iperf3_data.protocol, ATTR_REMOTE_HOST: self._iperf3_data.host, ATTR_REMOTE_PORT: self._iperf3_data.port, diff --git a/homeassistant/components/irish_rail_transport/sensor.py b/homeassistant/components/irish_rail_transport/sensor.py index 2035080b96d..d11a0b31809 100644 --- a/homeassistant/components/irish_rail_transport/sensor.py +++ b/homeassistant/components/irish_rail_transport/sensor.py @@ -7,7 +7,7 @@ from pyirishrail.pyirishrail import IrishRailRTPI 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 @@ -23,7 +23,6 @@ ATTR_DUE_AT = "Due at" ATTR_EXPECT_AT = "Expected at" ATTR_NEXT_UP = "Later Train" ATTR_TRAIN_TYPE = "Train type" -ATTRIBUTION = "Data provided by Irish Rail" CONF_STATION = "station" CONF_DESTINATION = "destination" @@ -76,6 +75,8 @@ def setup_platform( class IrishRailTransportSensor(SensorEntity): """Implementation of an irish rail public transport sensor.""" + _attr_attribution = "Data provided by Irish Rail" + def __init__(self, data, station, direction, destination, stops_at, name): """Initialize the sensor.""" self.data = data @@ -110,7 +111,6 @@ class IrishRailTransportSensor(SensorEntity): ) return { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_STATION: self._station, ATTR_ORIGIN: self._times[0][ATTR_ORIGIN], ATTR_DESTINATION: self._times[0][ATTR_DESTINATION], diff --git a/homeassistant/components/lastfm/sensor.py b/homeassistant/components/lastfm/sensor.py index 2675371f033..497ccf817bc 100644 --- a/homeassistant/components/lastfm/sensor.py +++ b/homeassistant/components/lastfm/sensor.py @@ -10,7 +10,7 @@ from pylast import WSError import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ATTR_ATTRIBUTION, CONF_API_KEY +from homeassistant.const import CONF_API_KEY from homeassistant.core import HomeAssistant import homeassistant.helpers.config_validation as cv from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -21,7 +21,6 @@ _LOGGER = logging.getLogger(__name__) ATTR_LAST_PLAYED = "last_played" ATTR_PLAY_COUNT = "play_count" ATTR_TOP_PLAYED = "top_played" -ATTRIBUTION = "Data provided by Last.fm" STATE_NOT_SCROBBLING = "Not Scrobbling" @@ -64,6 +63,8 @@ def setup_platform( class LastfmSensor(SensorEntity): """A class for the Last.fm account.""" + _attr_attribution = "Data provided by Last.fm" + def __init__(self, user, lastfm_api): """Initialize the sensor.""" self._unique_id = hashlib.sha256(user.encode("utf-8")).hexdigest() @@ -117,7 +118,6 @@ class LastfmSensor(SensorEntity): def extra_state_attributes(self): """Return the state attributes.""" return { - ATTR_ATTRIBUTION: ATTRIBUTION, ATTR_LAST_PLAYED: self._lastplayed, ATTR_PLAY_COUNT: self._playcount, ATTR_TOP_PLAYED: self._topplayed, diff --git a/homeassistant/components/logi_circle/camera.py b/homeassistant/components/logi_circle/camera.py index 733e49ca0bf..4a8b36a3d55 100644 --- a/homeassistant/components/logi_circle/camera.py +++ b/homeassistant/components/logi_circle/camera.py @@ -8,7 +8,6 @@ from homeassistant.components.camera import Camera, CameraEntityFeature from homeassistant.components.ffmpeg import get_ffmpeg_manager from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, ATTR_BATTERY_CHARGING, ATTR_BATTERY_LEVEL, ATTR_ENTITY_ID, @@ -62,6 +61,7 @@ async def async_setup_entry( class LogiCam(Camera): """An implementation of a Logi Circle camera.""" + _attr_attribution = ATTRIBUTION _attr_should_poll = True # Cameras default to False _attr_supported_features = CameraEntityFeature.ON_OFF @@ -141,7 +141,6 @@ class LogiCam(Camera): def extra_state_attributes(self): """Return the state attributes.""" state = { - ATTR_ATTRIBUTION: ATTRIBUTION, "battery_saving_mode": ( STATE_ON if self._camera.battery_saving else STATE_OFF ), diff --git a/homeassistant/components/logi_circle/sensor.py b/homeassistant/components/logi_circle/sensor.py index baf6d933916..b31a7bda2b2 100644 --- a/homeassistant/components/logi_circle/sensor.py +++ b/homeassistant/components/logi_circle/sensor.py @@ -7,7 +7,6 @@ from typing import Any from homeassistant.components.sensor import SensorEntity, SensorEntityDescription from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - ATTR_ATTRIBUTION, ATTR_BATTERY_CHARGING, CONF_MONITORED_CONDITIONS, CONF_SENSORS, @@ -58,6 +57,8 @@ async def async_setup_entry( class LogiSensor(SensorEntity): """A sensor implementation for a Logi Circle camera.""" + _attr_attribution = ATTRIBUTION + def __init__(self, camera, time_zone, description: SensorEntityDescription): """Initialize a sensor for Logi Circle camera.""" self.entity_description = description @@ -82,7 +83,6 @@ class LogiSensor(SensorEntity): def extra_state_attributes(self): """Return the state attributes.""" state = { - ATTR_ATTRIBUTION: ATTRIBUTION, "battery_saving_mode": ( STATE_ON if self._camera.battery_saving else STATE_OFF ), diff --git a/homeassistant/components/london_underground/sensor.py b/homeassistant/components/london_underground/sensor.py index b111fb8be6c..2cad8e9a109 100644 --- a/homeassistant/components/london_underground/sensor.py +++ b/homeassistant/components/london_underground/sensor.py @@ -9,7 +9,6 @@ from london_tube_status import TubeData import voluptuous as vol from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity -from homeassistant.const import ATTR_ATTRIBUTION from homeassistant.core import HomeAssistant from homeassistant.exceptions import PlatformNotReady from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -25,8 +24,6 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = "london_underground" -ATTRIBUTION = "Powered by TfL Open Data" - CONF_LINE = "line" ICON = "mdi:subway" @@ -102,11 +99,12 @@ class LondonTubeCoordinator(DataUpdateCoordinator): class LondonTubeSensor(CoordinatorEntity[LondonTubeCoordinator], SensorEntity): """Sensor that reads the status of a line from Tube Data.""" + _attr_attribution = "Powered by TfL Open Data" + def __init__(self, coordinator, name): """Initialize the London Underground sensor.""" super().__init__(coordinator) self._name = name - self.attrs = {ATTR_ATTRIBUTION: ATTRIBUTION} @property def name(self): @@ -126,5 +124,4 @@ class LondonTubeSensor(CoordinatorEntity[LondonTubeCoordinator], SensorEntity): @property def extra_state_attributes(self): """Return other details about the sensor state.""" - self.attrs["Description"] = self.coordinator.data[self.name]["Description"] - return self.attrs + return {"Description": self.coordinator.data[self.name]["Description"]}