diff --git a/homeassistant/components/sensor/random.py b/homeassistant/components/sensor/random.py index b9083245218..e57bbcc3955 100644 --- a/homeassistant/components/sensor/random.py +++ b/homeassistant/components/sensor/random.py @@ -9,14 +9,17 @@ import logging import voluptuous as vol -import homeassistant.helpers.config_validation as cv from homeassistant.components.sensor import PLATFORM_SCHEMA 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 _LOGGER = logging.getLogger(__name__) +ATTR_MAXIMUM = 'maximum' +ATTR_MINIMUM = 'minimum' + DEFAULT_NAME = 'Random Sensor' DEFAULT_MIN = 0 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) async_add_devices([RandomSensor(name, minimum, maximum, unit)], True) - return True class RandomSensor(Entity): """Representation of a Random number sensor.""" def __init__(self, name, minimum, maximum, unit_of_measurement): - """Initialize the sensor.""" + """Initialize the Random sensor.""" self._name = name self._minimum = minimum self._maximum = maximum @@ -74,6 +76,14 @@ class RandomSensor(Entity): """Return the unit this state is expressed in.""" 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 def async_update(self): """Get a new number and updates the states."""