Add attribution to Sense component (#33657)

This commit is contained in:
Marcelo Moreira de Mello 2020-04-04 16:51:00 -04:00 committed by GitHub
parent 22ae498f3a
commit d2e70eb967
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 2 deletions

View File

@ -2,12 +2,13 @@
import logging import logging
from homeassistant.components.binary_sensor import BinarySensorDevice 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.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity_registry import async_get_registry from homeassistant.helpers.entity_registry import async_get_registry
from .const import ( from .const import (
ATTRIBUTION,
DOMAIN, DOMAIN,
MDI_ICONS, MDI_ICONS,
SENSE_DATA, SENSE_DATA,
@ -100,6 +101,11 @@ class SenseDevice(BinarySensorDevice):
"""Return the old not so unique id of the binary sensor.""" """Return the old not so unique id of the binary sensor."""
return self._id return self._id
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {ATTR_ATTRIBUTION: ATTRIBUTION}
@property @property
def icon(self): def icon(self):
"""Return the icon of the binary sensor.""" """Return the icon of the binary sensor."""

View File

@ -16,6 +16,8 @@ SENSE_DISCOVERED_DEVICES_DATA = "sense_discovered_devices"
ACTIVE_NAME = "Energy" ACTIVE_NAME = "Energy"
ACTIVE_TYPE = "active" ACTIVE_TYPE = "active"
ATTRIBUTION = "Data provided by Sense.com"
CONSUMPTION_NAME = "Usage" CONSUMPTION_NAME = "Usage"
CONSUMPTION_ID = "usage" CONSUMPTION_ID = "usage"
PRODUCTION_NAME = "Production" PRODUCTION_NAME = "Production"

View File

@ -2,7 +2,12 @@
from datetime import timedelta from datetime import timedelta
import logging 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.core import callback
from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.dispatcher import async_dispatcher_connect
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
@ -11,6 +16,7 @@ from homeassistant.util import Throttle
from .const import ( from .const import (
ACTIVE_NAME, ACTIVE_NAME,
ACTIVE_TYPE, ACTIVE_TYPE,
ATTRIBUTION,
CONSUMPTION_ID, CONSUMPTION_ID,
CONSUMPTION_NAME, CONSUMPTION_NAME,
DOMAIN, DOMAIN,
@ -162,6 +168,11 @@ class SenseActiveSensor(Entity):
"""Return the unit of measurement of this entity, if any.""" """Return the unit of measurement of this entity, if any."""
return POWER_WATT return POWER_WATT
@property
def device_state_attributes(self):
"""Return the state attributes."""
return {ATTR_ATTRIBUTION: ATTRIBUTION}
@property @property
def icon(self): def icon(self):
"""Icon to use in the frontend, if any.""" """Icon to use in the frontend, if any."""