Add attributes (#11698)
parent
dce079e711
commit
d5f63ebac4
|
@ -9,14 +9,17 @@ import logging
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_NAME, CONF_MINIMUM, CONF_MAXIMUM, CONF_UNIT_OF_MEASUREMENT)
|
CONF_MAXIMUM, CONF_MINIMUM, CONF_NAME, CONF_UNIT_OF_MEASUREMENT)
|
||||||
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
ATTR_MAXIMUM = 'maximum'
|
||||||
|
ATTR_MINIMUM = 'minimum'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Random Sensor'
|
DEFAULT_NAME = 'Random Sensor'
|
||||||
DEFAULT_MIN = 0
|
DEFAULT_MIN = 0
|
||||||
DEFAULT_MAX = 20
|
DEFAULT_MAX = 20
|
||||||
|
@ -40,14 +43,13 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
|
||||||
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
|
unit = config.get(CONF_UNIT_OF_MEASUREMENT)
|
||||||
|
|
||||||
async_add_devices([RandomSensor(name, minimum, maximum, unit)], True)
|
async_add_devices([RandomSensor(name, minimum, maximum, unit)], True)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
class RandomSensor(Entity):
|
class RandomSensor(Entity):
|
||||||
"""Representation of a Random number sensor."""
|
"""Representation of a Random number sensor."""
|
||||||
|
|
||||||
def __init__(self, name, minimum, maximum, unit_of_measurement):
|
def __init__(self, name, minimum, maximum, unit_of_measurement):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the Random sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._minimum = minimum
|
self._minimum = minimum
|
||||||
self._maximum = maximum
|
self._maximum = maximum
|
||||||
|
@ -74,6 +76,14 @@ class RandomSensor(Entity):
|
||||||
"""Return the unit this state is expressed in."""
|
"""Return the unit this state is expressed in."""
|
||||||
return self._unit_of_measurement
|
return self._unit_of_measurement
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the attributes of the sensor."""
|
||||||
|
return {
|
||||||
|
ATTR_MAXIMUM: self._maximum,
|
||||||
|
ATTR_MINIMUM: self._minimum,
|
||||||
|
}
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def async_update(self):
|
def async_update(self):
|
||||||
"""Get a new number and updates the states."""
|
"""Get a new number and updates the states."""
|
||||||
|
|
Loading…
Reference in New Issue