From d2e70eb967b962a28bfdd43c9e5a7452919789b1 Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Sat, 4 Apr 2020 16:51:00 -0400 Subject: [PATCH] Add attribution to Sense component (#33657) --- homeassistant/components/sense/binary_sensor.py | 8 +++++++- homeassistant/components/sense/const.py | 2 ++ homeassistant/components/sense/sensor.py | 13 ++++++++++++- 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sense/binary_sensor.py b/homeassistant/components/sense/binary_sensor.py index 50fb3fd7dc7..e3e12e4a9f1 100644 --- a/homeassistant/components/sense/binary_sensor.py +++ b/homeassistant/components/sense/binary_sensor.py @@ -2,12 +2,13 @@ import logging from homeassistant.components.binary_sensor import BinarySensorDevice -from homeassistant.const import DEVICE_CLASS_POWER +from homeassistant.const import ATTR_ATTRIBUTION, DEVICE_CLASS_POWER from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity_registry import async_get_registry from .const import ( + ATTRIBUTION, DOMAIN, MDI_ICONS, SENSE_DATA, @@ -100,6 +101,11 @@ class SenseDevice(BinarySensorDevice): """Return the old not so unique id of the binary sensor.""" return self._id + @property + def device_state_attributes(self): + """Return the state attributes.""" + return {ATTR_ATTRIBUTION: ATTRIBUTION} + @property def icon(self): """Return the icon of the binary sensor.""" diff --git a/homeassistant/components/sense/const.py b/homeassistant/components/sense/const.py index 882c3c9d79f..66b21dbcac9 100644 --- a/homeassistant/components/sense/const.py +++ b/homeassistant/components/sense/const.py @@ -16,6 +16,8 @@ SENSE_DISCOVERED_DEVICES_DATA = "sense_discovered_devices" ACTIVE_NAME = "Energy" ACTIVE_TYPE = "active" +ATTRIBUTION = "Data provided by Sense.com" + CONSUMPTION_NAME = "Usage" CONSUMPTION_ID = "usage" PRODUCTION_NAME = "Production" diff --git a/homeassistant/components/sense/sensor.py b/homeassistant/components/sense/sensor.py index 06cfb90d2b5..d3cfb8b9db6 100644 --- a/homeassistant/components/sense/sensor.py +++ b/homeassistant/components/sense/sensor.py @@ -2,7 +2,12 @@ from datetime import timedelta import logging -from homeassistant.const import DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR, POWER_WATT +from homeassistant.const import ( + ATTR_ATTRIBUTION, + DEVICE_CLASS_POWER, + ENERGY_KILO_WATT_HOUR, + POWER_WATT, +) from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import Entity @@ -11,6 +16,7 @@ from homeassistant.util import Throttle from .const import ( ACTIVE_NAME, ACTIVE_TYPE, + ATTRIBUTION, CONSUMPTION_ID, CONSUMPTION_NAME, DOMAIN, @@ -162,6 +168,11 @@ class SenseActiveSensor(Entity): """Return the unit of measurement of this entity, if any.""" return POWER_WATT + @property + def device_state_attributes(self): + """Return the state attributes.""" + return {ATTR_ATTRIBUTION: ATTRIBUTION} + @property def icon(self): """Icon to use in the frontend, if any."""