Demo Sensor - Added device_class support (#14269)
This commit is contained in:
parent
c9de2f015b
commit
e68b52d50d
1 changed files with 11 additions and 3 deletions
|
@ -12,18 +12,21 @@ from homeassistant.helpers.entity import Entity
|
|||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the Demo sensors."""
|
||||
add_devices([
|
||||
DemoSensor('Outside Temperature', 15.6, TEMP_CELSIUS, 12),
|
||||
DemoSensor('Outside Humidity', 54, '%', None),
|
||||
DemoSensor('Outside Temperature', 15.6, 'temperature',
|
||||
TEMP_CELSIUS, 12),
|
||||
DemoSensor('Outside Humidity', 54, 'humidity', '%', None),
|
||||
])
|
||||
|
||||
|
||||
class DemoSensor(Entity):
|
||||
"""Representation of a Demo sensor."""
|
||||
|
||||
def __init__(self, name, state, unit_of_measurement, battery):
|
||||
def __init__(self, name, state, device_class,
|
||||
unit_of_measurement, battery):
|
||||
"""Initialize the sensor."""
|
||||
self._name = name
|
||||
self._state = state
|
||||
self._device_class = device_class
|
||||
self._unit_of_measurement = unit_of_measurement
|
||||
self._battery = battery
|
||||
|
||||
|
@ -32,6 +35,11 @@ class DemoSensor(Entity):
|
|||
"""No polling needed for a demo sensor."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
|
|
Loading…
Add table
Reference in a new issue