From e68b52d50d6bb3a1696d168f7df45b8ab639c22f Mon Sep 17 00:00:00 2001 From: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Thu, 3 May 2018 19:51:36 +0200 Subject: [PATCH] Demo Sensor - Added device_class support (#14269) --- homeassistant/components/sensor/demo.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/sensor/demo.py b/homeassistant/components/sensor/demo.py index ba7c93203df..5cae1a47c23 100644 --- a/homeassistant/components/sensor/demo.py +++ b/homeassistant/components/sensor/demo.py @@ -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."""