Add/adjust attribution of sensor platform (#3719)
* Add/adjust attribution * Fix typo
This commit is contained in:
parent
7cf2c48175
commit
8ded8f572a
12 changed files with 101 additions and 57 deletions
|
@ -11,16 +11,17 @@ import requests
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import Throttle
|
||||
from homeassistant.const import (
|
||||
CONF_MONITORED_CONDITIONS, TEMP_CELSIUS,
|
||||
STATE_UNKNOWN, CONF_NAME)
|
||||
CONF_MONITORED_CONDITIONS, TEMP_CELSIUS, STATE_UNKNOWN, CONF_NAME,
|
||||
ATTR_ATTRIBUTION)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_RESOURCE = 'http://www.bom.gov.au/fwo/{}/{}.{}.json'
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Data provided by the Australian Bureau of Meteorology"
|
||||
CONF_ZONE_ID = 'zone_id'
|
||||
CONF_WMO_ID = 'wmo_id'
|
||||
|
||||
|
@ -75,7 +76,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup the BOM sensor."""
|
||||
"""Set up the BOM sensor."""
|
||||
rest = BOMCurrentData(
|
||||
hass, config.get(CONF_ZONE_ID), config.get(CONF_WMO_ID))
|
||||
|
||||
|
@ -96,7 +97,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
|
||||
|
||||
class BOMCurrentSensor(Entity):
|
||||
"""Implementing the BOM current sensor."""
|
||||
"""Implementation of a BOM current sensor."""
|
||||
|
||||
def __init__(self, rest, condition, stationname):
|
||||
"""Initialize the sensor."""
|
||||
|
@ -131,6 +132,7 @@ class BOMCurrentSensor(Entity):
|
|||
attr['Station Name'] = self.rest.data['name']
|
||||
attr['Last Update'] = datetime.datetime.strptime(str(
|
||||
self.rest.data['local_date_time_full']), '%Y%m%d%H%M%S')
|
||||
attr[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION
|
||||
return attr
|
||||
|
||||
@property
|
||||
|
|
|
@ -12,9 +12,10 @@ from urllib.error import HTTPError
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.const import ATTR_ATTRIBUTION
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
REQUIREMENTS = ['coinmarketcap==2.0.1']
|
||||
|
||||
|
@ -30,6 +31,7 @@ ATTR_PRICE = 'price_usd'
|
|||
ATTR_SYMBOL = 'symbol'
|
||||
ATTR_TOTAL_SUPPLY = 'total_supply'
|
||||
|
||||
CONF_ATTRIBUTION = "Data provided by CoinMarketCap"
|
||||
CONF_CURRENCY = 'currency'
|
||||
|
||||
DEFAULT_CURRENCY = 'bitcoin'
|
||||
|
@ -89,7 +91,7 @@ class CoinMarketCapSensor(Entity):
|
|||
return ICON
|
||||
|
||||
@property
|
||||
def state_attributes(self):
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes of the sensor."""
|
||||
return {
|
||||
ATTR_24H_VOLUME_USD: self._ticker.get('24h_volume_usd'),
|
||||
|
@ -99,6 +101,7 @@ class CoinMarketCapSensor(Entity):
|
|||
ATTR_PERCENT_CHANGE_7D: self._ticker.get('percent_change_7d'),
|
||||
ATTR_SYMBOL: self._ticker.get('symbol'),
|
||||
ATTR_TOTAL_SUPPLY: self._ticker.get('total_supply'),
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
|
|
|
@ -13,7 +13,7 @@ from requests.exceptions import ConnectionError as ConnectError, \
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS)
|
||||
CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -22,6 +22,7 @@ REQUIREMENTS = ['python-forecastio==1.3.5']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Powered by Dark Sky"
|
||||
CONF_UNITS = 'units'
|
||||
CONF_UPDATE_INTERVAL = 'update_interval'
|
||||
|
||||
|
@ -178,6 +179,13 @@ class DarkSkySensor(Entity):
|
|||
"""Icon to use in the frontend, if any."""
|
||||
return SENSOR_TYPES[self.type][6]
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
# pylint: disable=too-many-branches,too-many-statements
|
||||
def update(self):
|
||||
"""Get the latest data from Dark Sky and updates the states."""
|
||||
|
|
|
@ -10,7 +10,7 @@ from datetime import timedelta
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -19,6 +19,11 @@ REQUIREMENTS = ['fixerio==0.1.1']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
ATTR_BASE = 'Base currency'
|
||||
ATTR_EXCHANGE_RATE = 'Exchange rate'
|
||||
ATTR_TARGET = 'Target currency'
|
||||
|
||||
CONF_ATTRIBUTION = "Data provided by the European Central Bank (ECB)"
|
||||
CONF_BASE = 'base'
|
||||
CONF_TARGET = 'target'
|
||||
|
||||
|
@ -29,10 +34,6 @@ ICON = 'mdi:currency'
|
|||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(days=1)
|
||||
|
||||
STATE_ATTR_BASE = 'Base currency'
|
||||
STATE_ATTR_EXCHANGE_RATE = 'Exchange rate'
|
||||
STATE_ATTR_TARGET = 'Target currency'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_TARGET): cv.string,
|
||||
vol.Optional(CONF_BASE, default=DEFAULT_BASE): cv.string,
|
||||
|
@ -90,9 +91,10 @@ class ExchangeRateSensor(Entity):
|
|||
"""Return the state attributes."""
|
||||
if self.data.rate is not None:
|
||||
return {
|
||||
STATE_ATTR_BASE: self.data.rate['base'],
|
||||
STATE_ATTR_TARGET: self._target,
|
||||
STATE_ATTR_EXCHANGE_RATE: self.data.rate['rates'][self._target]
|
||||
ATTR_BASE: self.data.rate['base'],
|
||||
ATTR_TARGET: self._target,
|
||||
ATTR_EXCHANGE_RATE: self.data.rate['rates'][self._target],
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
|
@ -12,7 +12,7 @@ import voluptuous as vol
|
|||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_API_KEY, CONF_NAME, TEMP_CELSIUS, TEMP_FAHRENHEIT,
|
||||
CONF_MONITORED_CONDITIONS)
|
||||
CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -21,6 +21,7 @@ REQUIREMENTS = ['pyowm==2.5.0']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Data provied by OpenWeatherMap"
|
||||
CONF_FORECAST = 'forecast'
|
||||
|
||||
DEFAULT_NAME = 'OWM'
|
||||
|
@ -113,6 +114,13 @@ class OpenWeatherMapSensor(Entity):
|
|||
"""Return the unit of measurement of this entity, if any."""
|
||||
return self._unit_of_measurement
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
# pylint: disable=too-many-branches
|
||||
def update(self):
|
||||
"""Get the latest data from OWM and updates the states."""
|
||||
|
|
|
@ -11,7 +11,8 @@ import voluptuous as vol
|
|||
import requests
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (TEMP_CELSIUS, CONF_NAME, STATE_UNKNOWN)
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, CONF_NAME, STATE_UNKNOWN, ATTR_ATTRIBUTION)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -22,19 +23,23 @@ _LOGGER = logging.getLogger(__name__)
|
|||
_RESOURCE = 'http://www.hydrodata.ch/xml/SMS.xml'
|
||||
|
||||
CONF_STATION = 'station'
|
||||
CONF_ATTRIBUTION = "Data provided by the Swiss Federal Office for the " \
|
||||
"Environment FOEN"
|
||||
|
||||
DEFAULT_NAME = 'Water temperature'
|
||||
|
||||
ICON = 'mdi:cup-water'
|
||||
|
||||
ATTR_LOCATION = 'Location'
|
||||
ATTR_UPDATE = 'Update'
|
||||
ATTR_DISCHARGE = 'Discharge'
|
||||
ATTR_WATERLEVEL = 'Level'
|
||||
ATTR_DISCHARGE_MEAN = 'Discharge mean'
|
||||
ATTR_WATERLEVEL_MEAN = 'Level mean'
|
||||
ATTR_TEMPERATURE_MEAN = 'Temperature mean'
|
||||
ATTR_DISCHARGE_MAX = 'Discharge max'
|
||||
ATTR_WATERLEVEL_MAX = 'Level max'
|
||||
ATTR_TEMPERATURE_MAX = 'Temperature max'
|
||||
ATTR_LOCATION = 'location'
|
||||
ATTR_UPDATE = 'update'
|
||||
ATTR_DISCHARGE = 'discharge'
|
||||
ATTR_WATERLEVEL = 'level'
|
||||
ATTR_DISCHARGE_MEAN = 'discharge_mean'
|
||||
ATTR_WATERLEVEL_MEAN = 'level_mean'
|
||||
ATTR_TEMPERATURE_MEAN = 'temperature_mean'
|
||||
ATTR_DISCHARGE_MAX = 'discharge_max'
|
||||
ATTR_WATERLEVEL_MAX = 'level_max'
|
||||
ATTR_TEMPERATURE_MAX = 'temperature_max'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Required(CONF_STATION): vol.Coerce(int),
|
||||
|
@ -125,6 +130,7 @@ class SwissHydrologicalDataSensor(Entity):
|
|||
|
||||
attributes[ATTR_LOCATION] = self.data.measurings['location']
|
||||
attributes[ATTR_UPDATE] = self.data.measurings['update_time']
|
||||
attributes[ATTR_ATTRIBUTION] = CONF_ATTRIBUTION
|
||||
return attributes
|
||||
|
||||
@property
|
||||
|
|
|
@ -11,7 +11,7 @@ import requests
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION
|
||||
import homeassistant.util.dt as dt_util
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -20,12 +20,13 @@ import homeassistant.helpers.config_validation as cv
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
_RESOURCE = 'http://transport.opendata.ch/v1/'
|
||||
|
||||
ATTR_DEPARTURE_TIME1 = 'Next departure'
|
||||
ATTR_DEPARTURE_TIME2 = 'Next on departure'
|
||||
ATTR_REMAINING_TIME = 'Remaining time'
|
||||
ATTR_START = 'Start'
|
||||
ATTR_TARGET = 'Destination'
|
||||
ATTR_DEPARTURE_TIME1 = 'next_departure'
|
||||
ATTR_DEPARTURE_TIME2 = 'next_on_departure'
|
||||
ATTR_REMAINING_TIME = 'remaining_time'
|
||||
ATTR_START = 'start'
|
||||
ATTR_TARGET = 'destination'
|
||||
|
||||
CONF_ATTRIBUTION = "Data provided by transport.opendata.ch"
|
||||
CONF_DESTINATION = 'to'
|
||||
CONF_START = 'from'
|
||||
|
||||
|
@ -96,7 +97,8 @@ class SwissPublicTransportSensor(Entity):
|
|||
ATTR_START: self._from,
|
||||
ATTR_TARGET: self._to,
|
||||
ATTR_REMAINING_TIME: '{}'.format(
|
||||
':'.join(str(self._times[2]).split(':')[:2]))
|
||||
':'.join(str(self._times[2]).split(':')[:2])),
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
|
@ -11,16 +11,17 @@ import requests
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.util import Throttle
|
||||
from homeassistant.const import (
|
||||
CONF_MONITORED_CONDITIONS, CONF_API_KEY, TEMP_FAHRENHEIT, TEMP_CELSIUS,
|
||||
STATE_UNKNOWN)
|
||||
STATE_UNKNOWN, ATTR_ATTRIBUTION)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
||||
_RESOURCE = 'http://api.wunderground.com/api/{}/conditions/q/'
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Data provided by the WUnderground weather service"
|
||||
CONF_PWS_ID = 'pws_id'
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=300)
|
||||
|
@ -108,6 +109,13 @@ class WUndergroundSensor(Entity):
|
|||
else:
|
||||
return STATE_UNKNOWN
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
@property
|
||||
def entity_picture(self):
|
||||
"""Return the entity picture."""
|
||||
|
@ -123,9 +131,8 @@ class WUndergroundSensor(Entity):
|
|||
"""Update current conditions."""
|
||||
self.rest.update()
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
|
||||
|
||||
class WUndergroundData(object):
|
||||
"""Get data from WUnderground."""
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ from datetime import timedelta
|
|||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.const import CONF_NAME, ATTR_ATTRIBUTION
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
|
@ -19,7 +19,9 @@ REQUIREMENTS = ['yahoo-finance==1.2.1']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Stock market information provided by Yahoo! Inc."
|
||||
CONF_SYMBOL = 'symbol'
|
||||
|
||||
DEFAULT_SYMBOL = 'YHOO'
|
||||
DEFAULT_NAME = 'Yahoo Stock'
|
||||
|
||||
|
@ -28,8 +30,8 @@ ICON = 'mdi:currency-usd'
|
|||
MIN_TIME_BETWEEN_UPDATES = timedelta(minutes=1)
|
||||
|
||||
ATTR_CHANGE = 'Change'
|
||||
ATTR_OPEN = 'Open'
|
||||
ATTR_PREV_CLOSE = 'Prev. Close'
|
||||
ATTR_OPEN = 'open'
|
||||
ATTR_PREV_CLOSE = 'prev_close'
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_SYMBOL, default=DEFAULT_SYMBOL): cv.string,
|
||||
|
@ -82,10 +84,7 @@ class YahooFinanceSensor(Entity):
|
|||
ATTR_CHANGE: self.data.price_change,
|
||||
ATTR_OPEN: self.data.price_open,
|
||||
ATTR_PREV_CLOSE: self.data.prev_close,
|
||||
'About': "Stock market information delivered by Yahoo!"
|
||||
" Inc. are provided free of charge for use"
|
||||
" by individuals and non-profit organizations"
|
||||
" for personal, non-commercial uses."
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
|
@ -5,13 +5,15 @@ For more details about this platform, please refer to the documentation at
|
|||
https://home-assistant.io/components/sensor.yr/
|
||||
"""
|
||||
import logging
|
||||
|
||||
import requests
|
||||
import voluptuous as vol
|
||||
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_ELEVATION, CONF_MONITORED_CONDITIONS)
|
||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_ELEVATION, CONF_MONITORED_CONDITIONS,
|
||||
ATTR_ATTRIBUTION)
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
|
@ -19,6 +21,9 @@ REQUIREMENTS = ['xmltodict==0.10.2']
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Weather forecast from yr.no, delivered by the Norwegian " \
|
||||
"Meteorological Institute and the NRK."
|
||||
|
||||
# Sensor types are defined like so:
|
||||
SENSOR_TYPES = {
|
||||
'symbol': ['Symbol', None],
|
||||
|
@ -108,8 +113,7 @@ class YrSensor(Entity):
|
|||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
'about': "Weather forecast from yr.no, delivered by the"
|
||||
" Norwegian Meteorological Institute and the NRK"
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
@property
|
||||
|
|
|
@ -11,7 +11,8 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||
from homeassistant.const import (
|
||||
TEMP_CELSIUS, CONF_MONITORED_CONDITIONS, CONF_NAME, STATE_UNKNOWN)
|
||||
TEMP_CELSIUS, CONF_MONITORED_CONDITIONS, CONF_NAME, STATE_UNKNOWN,
|
||||
ATTR_ATTRIBUTION)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.util import Throttle
|
||||
|
@ -20,6 +21,7 @@ REQUIREMENTS = ["yahooweather==0.8"]
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
CONF_ATTRIBUTION = "Weather details provided by Yahoo! Inc."
|
||||
CONF_FORECAST = 'forecast'
|
||||
CONF_WOEID = 'woeid'
|
||||
|
||||
|
@ -140,9 +142,7 @@ class YahooWeatherSensor(Entity):
|
|||
def device_state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
return {
|
||||
'about': "Weather forecast delivered by Yahoo! Inc. are provided"
|
||||
" free of charge for use by individuals and non-profit"
|
||||
" organizations for personal, non-commercial uses."
|
||||
ATTR_ATTRIBUTION: CONF_ATTRIBUTION,
|
||||
}
|
||||
|
||||
def update(self):
|
||||
|
|
|
@ -173,6 +173,9 @@ STATE_UNLOCKED = 'unlocked'
|
|||
STATE_UNAVAILABLE = 'unavailable'
|
||||
|
||||
# #### STATE AND EVENT ATTRIBUTES ####
|
||||
# Attribution
|
||||
ATTR_ATTRIBUTION = 'attribution'
|
||||
|
||||
# Contains current time for a TIME_CHANGED event
|
||||
ATTR_NOW = 'now'
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue