Move attribution to standalone attribute [r-s] (#80520)
* Move attribution to standalone attribute [r-s] * Fix test
This commit is contained in:
parent
6b56336e52
commit
c37e4b870f
10 changed files with 28 additions and 52 deletions
|
@ -8,7 +8,6 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
CONF_PASSWORD,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_USERNAME,
|
||||
|
@ -27,8 +26,6 @@ _LOGGER = logging.getLogger(__name__)
|
|||
|
||||
ALLOWED_WATERING_TIME = [5, 10, 15, 30, 45, 60]
|
||||
|
||||
ATTRIBUTION = "Data provided by Melnor Aquatimer.com"
|
||||
|
||||
CONF_WATERING_TIME = "watering_minutes"
|
||||
|
||||
NOTIFICATION_ID = "raincloud_notification"
|
||||
|
@ -140,6 +137,8 @@ class RainCloudHub:
|
|||
class RainCloudEntity(Entity):
|
||||
"""Entity class for RainCloud devices."""
|
||||
|
||||
_attr_attribution = "Data provided by Melnor Aquatimer.com"
|
||||
|
||||
def __init__(self, data, sensor_type):
|
||||
"""Initialize the RainCloud entity."""
|
||||
self.data = data
|
||||
|
@ -167,7 +166,7 @@ class RainCloudEntity(Entity):
|
|||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {ATTR_ATTRIBUTION: ATTRIBUTION, "identifier": self.data.serial}
|
||||
return {"identifier": self.data.serial}
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
|
|
|
@ -7,7 +7,7 @@ from typing import Any
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.switch import PLATFORM_SCHEMA, SwitchEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -15,7 +15,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|||
|
||||
from . import (
|
||||
ALLOWED_WATERING_TIME,
|
||||
ATTRIBUTION,
|
||||
CONF_WATERING_TIME,
|
||||
DATA_RAINCLOUD,
|
||||
DEFAULT_WATERING_TIME,
|
||||
|
@ -97,7 +96,6 @@ class RainCloudSwitch(RainCloudEntity, SwitchEntity):
|
|||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
"default_manual_timer": self._default_watering_timer,
|
||||
"identifier": self.data.serial,
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import rjpl
|
|||
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
|
||||
|
@ -37,8 +37,6 @@ ATTR_REAL_TIME_AT = "real_time_at"
|
|||
ATTR_TRACK = "track"
|
||||
ATTR_NEXT_UP = "next_departures"
|
||||
|
||||
ATTRIBUTION = "Data provided by rejseplanen.dk"
|
||||
|
||||
CONF_STOP_ID = "stop_id"
|
||||
CONF_ROUTE = "route"
|
||||
CONF_DIRECTION = "direction"
|
||||
|
@ -100,6 +98,8 @@ def setup_platform(
|
|||
class RejseplanenTransportSensor(SensorEntity):
|
||||
"""Implementation of Rejseplanen transport sensor."""
|
||||
|
||||
_attr_attribution = "Data provided by rejseplanen.dk"
|
||||
|
||||
def __init__(self, data, stop_id, route, direction, name):
|
||||
"""Initialize the sensor."""
|
||||
self.data = data
|
||||
|
@ -123,14 +123,13 @@ class RejseplanenTransportSensor(SensorEntity):
|
|||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if not self._times:
|
||||
return {ATTR_STOP_ID: self._stop_id, ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
return {ATTR_STOP_ID: self._stop_id}
|
||||
|
||||
next_up = []
|
||||
if len(self._times) > 1:
|
||||
next_up = self._times[1:]
|
||||
|
||||
attributes = {
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
ATTR_NEXT_UP: next_up,
|
||||
ATTR_STOP_ID: self._stop_id,
|
||||
}
|
||||
|
|
|
@ -7,14 +7,12 @@ from pyripple import get_balance
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_ADDRESS, CONF_NAME
|
||||
from homeassistant.const import CONF_ADDRESS, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
ATTRIBUTION = "Data provided by ripple.com"
|
||||
|
||||
DEFAULT_NAME = "Ripple Balance"
|
||||
|
||||
SCAN_INTERVAL = timedelta(minutes=5)
|
||||
|
@ -43,6 +41,8 @@ def setup_platform(
|
|||
class RippleSensor(SensorEntity):
|
||||
"""Representation of an Ripple.com sensor."""
|
||||
|
||||
_attr_attribution = "Data provided by ripple.com"
|
||||
|
||||
def __init__(self, name, address):
|
||||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
|
@ -65,11 +65,6 @@ class RippleSensor(SensorEntity):
|
|||
"""Return the unit of measurement this sensor expresses itself in."""
|
||||
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:
|
||||
"""Get the latest state of the sensor."""
|
||||
if (balance := get_balance(self.address)) is not None:
|
||||
|
|
|
@ -6,7 +6,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, callback
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -73,6 +72,7 @@ def sense_to_mdi(sense_icon):
|
|||
class SenseDevice(BinarySensorEntity):
|
||||
"""Implementation of a Sense energy device binary sensor."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, sense_devices_data, device, sense_monitor_id):
|
||||
|
@ -111,11 +111,6 @@ class SenseDevice(BinarySensorEntity):
|
|||
"""Return the old not so unique id of the binary sensor."""
|
||||
return self._id
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon of the binary sensor."""
|
||||
|
|
|
@ -11,7 +11,6 @@ import voluptuous as vol
|
|||
from homeassistant.components import persistent_notification
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import (
|
||||
ATTR_ATTRIBUTION,
|
||||
ATTR_FRIENDLY_NAME,
|
||||
ATTR_LOCATION,
|
||||
CONF_PASSWORD,
|
||||
|
@ -112,12 +111,13 @@ async def async_setup_platform(
|
|||
class SeventeenTrackSummarySensor(SensorEntity):
|
||||
"""Define a summary sensor."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_icon = "mdi:package"
|
||||
_attr_native_unit_of_measurement = "packages"
|
||||
|
||||
def __init__(self, data, status, initial_state):
|
||||
"""Initialize."""
|
||||
self._attr_extra_state_attributes = {ATTR_ATTRIBUTION: ATTRIBUTION}
|
||||
self._attr_extra_state_attributes = {}
|
||||
self._data = data
|
||||
self._state = initial_state
|
||||
self._status = status
|
||||
|
@ -164,12 +164,12 @@ class SeventeenTrackSummarySensor(SensorEntity):
|
|||
class SeventeenTrackPackageSensor(SensorEntity):
|
||||
"""Define an individual package sensor."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_icon = "mdi:package"
|
||||
|
||||
def __init__(self, data, package):
|
||||
"""Initialize."""
|
||||
self._attr_extra_state_attributes = {
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
ATTR_DESTINATION_COUNTRY: package.destination_country,
|
||||
ATTR_INFO_TEXT: package.info_text,
|
||||
ATTR_TIMESTAMP: package.timestamp,
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
||||
|
@ -83,6 +83,7 @@ async def async_setup_entry(
|
|||
class SrpEntity(SensorEntity):
|
||||
"""Implementation of a Srp Energy Usage sensor."""
|
||||
|
||||
_attr_attribution = ATTRIBUTION
|
||||
_attr_should_poll = False
|
||||
|
||||
def __init__(self, coordinator):
|
||||
|
@ -127,17 +128,6 @@ class SrpEntity(SensorEntity):
|
|||
return f"{self.coordinator.data:.2f}"
|
||||
return None
|
||||
|
||||
@property
|
||||
def extra_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
if not self.coordinator.data:
|
||||
return None
|
||||
attributes = {
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
}
|
||||
|
||||
return attributes
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return if entity is available."""
|
||||
|
|
|
@ -8,7 +8,7 @@ from swisshydrodata import SwissHydroData
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.const import CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -17,8 +17,6 @@ from homeassistant.util import Throttle
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTRIBUTION = "Data provided by the Swiss Federal Office for the Environment FOEN"
|
||||
|
||||
ATTR_MAX_24H = "max-24h"
|
||||
ATTR_MEAN_24H = "mean-24h"
|
||||
ATTR_MIN_24H = "min-24h"
|
||||
|
@ -85,6 +83,10 @@ def setup_platform(
|
|||
class SwissHydrologicalDataSensor(SensorEntity):
|
||||
"""Implementation of a Swiss hydrological sensor."""
|
||||
|
||||
_attr_attribution = (
|
||||
"Data provided by the Swiss Federal Office for the Environment FOEN"
|
||||
)
|
||||
|
||||
def __init__(self, hydro_data, station, condition):
|
||||
"""Initialize the Swiss hydrological sensor."""
|
||||
self.hydro_data = hydro_data
|
||||
|
@ -123,7 +125,7 @@ class SwissHydrologicalDataSensor(SensorEntity):
|
|||
attrs = {}
|
||||
|
||||
if not self._data:
|
||||
attrs[ATTR_ATTRIBUTION] = ATTRIBUTION
|
||||
|
||||
return attrs
|
||||
|
||||
attrs[ATTR_WATER_BODY_TYPE] = self._data["water-body-type"]
|
||||
|
@ -131,7 +133,6 @@ class SwissHydrologicalDataSensor(SensorEntity):
|
|||
attrs[ATTR_STATION_UPDATE] = self._data["parameters"][self._condition][
|
||||
"datetime"
|
||||
]
|
||||
attrs[ATTR_ATTRIBUTION] = ATTRIBUTION
|
||||
|
||||
for entry in CONDITION_DETAILS:
|
||||
attrs[entry.replace("-", "_")] = self._data["parameters"][self._condition][
|
||||
|
|
|
@ -9,7 +9,7 @@ from opendata_transport.exceptions import OpendataTransportError
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_NAME
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -30,8 +30,6 @@ ATTR_TRAIN_NUMBER = "train_number"
|
|||
ATTR_TRANSFERS = "transfers"
|
||||
ATTR_DELAY = "delay"
|
||||
|
||||
ATTRIBUTION = "Data provided by transport.opendata.ch"
|
||||
|
||||
CONF_DESTINATION = "to"
|
||||
CONF_START = "from"
|
||||
|
||||
|
@ -80,6 +78,8 @@ async def async_setup_platform(
|
|||
class SwissPublicTransportSensor(SensorEntity):
|
||||
"""Implementation of an Swiss public transport sensor."""
|
||||
|
||||
_attr_attribution = "Data provided by transport.opendata.ch"
|
||||
|
||||
def __init__(self, opendata, start, destination, name):
|
||||
"""Initialize the sensor."""
|
||||
self._opendata = opendata
|
||||
|
@ -122,7 +122,6 @@ class SwissPublicTransportSensor(SensorEntity):
|
|||
ATTR_START: self._opendata.from_name,
|
||||
ATTR_TARGET: self._opendata.to_name,
|
||||
ATTR_REMAINING_TIME: f"{self._remaining_time}",
|
||||
ATTR_ATTRIBUTION: ATTRIBUTION,
|
||||
ATTR_DELAY: self._opendata.connections[0]["delay"],
|
||||
}
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.srp_energy.const import (
|
|||
SRP_ENERGY_DOMAIN,
|
||||
)
|
||||
from homeassistant.components.srp_energy.sensor import SrpEntity, async_setup_entry
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, ENERGY_KILO_WATT_HOUR
|
||||
from homeassistant.const import ENERGY_KILO_WATT_HOUR
|
||||
|
||||
|
||||
async def test_async_setup_entry(hass):
|
||||
|
@ -93,7 +93,7 @@ async def test_srp_entity(hass):
|
|||
assert srp_entity.icon == ICON
|
||||
assert srp_entity.usage == "2.00"
|
||||
assert srp_entity.should_poll is False
|
||||
assert srp_entity.extra_state_attributes[ATTR_ATTRIBUTION] == ATTRIBUTION
|
||||
assert srp_entity.attribution == ATTRIBUTION
|
||||
assert srp_entity.available is not None
|
||||
assert srp_entity.device_class is SensorDeviceClass.ENERGY
|
||||
assert srp_entity.state_class is SensorStateClass.TOTAL_INCREASING
|
||||
|
|
Loading…
Add table
Reference in a new issue