Add device_class_power to sensor (#22691)

* Add device_class_power to sensor

* Fix comment
This commit is contained in:
Markus Jankowski 2019-04-04 06:52:23 +02:00 committed by Paulus Schoutsen
parent a5a926bcc6
commit 8e39939b7e
3 changed files with 14 additions and 6 deletions

View File

@ -2,8 +2,8 @@
import logging
from homeassistant.const import (
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_TEMPERATURE,
POWER_WATT, TEMP_CELSIUS)
DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE, DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE, POWER_WATT, TEMP_CELSIUS)
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
@ -238,6 +238,11 @@ class HomematicipPowerSensor(HomematicipGenericDevice):
"""Initialize the device."""
super().__init__(home, device, 'Power')
@property
def device_class(self):
"""Return the device class of the sensor."""
return DEVICE_CLASS_POWER
@property
def state(self):
"""Represenation of the HomematicIP power comsumption value."""

View File

@ -5,12 +5,13 @@ import logging
import voluptuous as vol
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.config_validation import ( # noqa
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
from homeassistant.const import (
DEVICE_CLASS_BATTERY, DEVICE_CLASS_HUMIDITY, DEVICE_CLASS_ILLUMINANCE,
DEVICE_CLASS_TEMPERATURE, DEVICE_CLASS_TIMESTAMP, DEVICE_CLASS_PRESSURE)
DEVICE_CLASS_POWER, DEVICE_CLASS_PRESSURE, DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP)
from homeassistant.helpers.config_validation import ( # noqa
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE)
from homeassistant.helpers.entity_component import EntityComponent
_LOGGER = logging.getLogger(__name__)
@ -26,6 +27,7 @@ DEVICE_CLASSES = [
DEVICE_CLASS_TEMPERATURE, # temperature (C/F)
DEVICE_CLASS_TIMESTAMP, # timestamp (ISO8601)
DEVICE_CLASS_PRESSURE, # pressure (hPa/mbar)
DEVICE_CLASS_POWER, # power (W/kW)
]
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES))

View File

@ -188,6 +188,7 @@ DEVICE_CLASS_ILLUMINANCE = 'illuminance'
DEVICE_CLASS_TEMPERATURE = 'temperature'
DEVICE_CLASS_TIMESTAMP = 'timestamp'
DEVICE_CLASS_PRESSURE = 'pressure'
DEVICE_CLASS_POWER = 'power'
# #### STATES ####
STATE_ON = 'on'