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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Set up the Demo sensors."""
|
"""Set up the Demo sensors."""
|
||||||
add_devices([
|
add_devices([
|
||||||
DemoSensor('Outside Temperature', 15.6, TEMP_CELSIUS, 12),
|
DemoSensor('Outside Temperature', 15.6, 'temperature',
|
||||||
DemoSensor('Outside Humidity', 54, '%', None),
|
TEMP_CELSIUS, 12),
|
||||||
|
DemoSensor('Outside Humidity', 54, 'humidity', '%', None),
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
class DemoSensor(Entity):
|
class DemoSensor(Entity):
|
||||||
"""Representation of a Demo sensor."""
|
"""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."""
|
"""Initialize the sensor."""
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = state
|
self._state = state
|
||||||
|
self._device_class = device_class
|
||||||
self._unit_of_measurement = unit_of_measurement
|
self._unit_of_measurement = unit_of_measurement
|
||||||
self._battery = battery
|
self._battery = battery
|
||||||
|
|
||||||
|
@ -32,6 +35,11 @@ class DemoSensor(Entity):
|
||||||
"""No polling needed for a demo sensor."""
|
"""No polling needed for a demo sensor."""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class of the sensor."""
|
||||||
|
return self._device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of the sensor."""
|
"""Return the name of the sensor."""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue