diff --git a/homeassistant/components/demo/sensor.py b/homeassistant/components/demo/sensor.py index 7607bad4e1c..00111d34dd4 100644 --- a/homeassistant/components/demo/sensor.py +++ b/homeassistant/components/demo/sensor.py @@ -1,5 +1,5 @@ """Demo platform that has a couple of fake sensors.""" -from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity from homeassistant.const import ( ATTR_BATTERY_LEVEL, CONCENTRATION_PARTS_PER_MILLION, @@ -23,6 +23,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "Outside Temperature", 15.6, DEVICE_CLASS_TEMPERATURE, + STATE_CLASS_MEASUREMENT, TEMP_CELSIUS, 12, ), @@ -31,6 +32,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "Outside Humidity", 54, DEVICE_CLASS_HUMIDITY, + STATE_CLASS_MEASUREMENT, PERCENTAGE, None, ), @@ -39,6 +41,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "Carbon monoxide", 54, DEVICE_CLASS_CO, + STATE_CLASS_MEASUREMENT, CONCENTRATION_PARTS_PER_MILLION, None, ), @@ -47,6 +50,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= "Carbon dioxide", 54, DEVICE_CLASS_CO2, + STATE_CLASS_MEASUREMENT, CONCENTRATION_PARTS_PER_MILLION, 14, ), @@ -63,15 +67,23 @@ class DemoSensor(SensorEntity): """Representation of a Demo sensor.""" def __init__( - self, unique_id, name, state, device_class, unit_of_measurement, battery + self, + unique_id, + name, + state, + device_class, + state_class, + unit_of_measurement, + battery, ): """Initialize the sensor.""" - self._unique_id = unique_id + self._battery = battery + self._device_class = device_class self._name = name self._state = state - self._device_class = device_class + self._state_class = state_class + self._unique_id = unique_id self._unit_of_measurement = unit_of_measurement - self._battery = battery @property def device_info(self): @@ -99,6 +111,11 @@ class DemoSensor(SensorEntity): """Return the device class of the sensor.""" return self._device_class + @property + def state_class(self): + """Return the state class of the sensor.""" + return self._state_class + @property def name(self): """Return the name of the sensor.""" diff --git a/tests/components/prometheus/test_init.py b/tests/components/prometheus/test_init.py index fe91c7c0002..b1abe1de3e5 100644 --- a/tests/components/prometheus/test_init.py +++ b/tests/components/prometheus/test_init.py @@ -47,14 +47,14 @@ async def prometheus_client(hass, hass_client): ) sensor1 = DemoSensor( - None, "Television Energy", 74, None, ENERGY_KILO_WATT_HOUR, None + None, "Television Energy", 74, None, None, ENERGY_KILO_WATT_HOUR, None ) sensor1.hass = hass sensor1.entity_id = "sensor.television_energy" await sensor1.async_update_ha_state() sensor2 = DemoSensor( - None, "Radio Energy", 14, DEVICE_CLASS_POWER, ENERGY_KILO_WATT_HOUR, None + None, "Radio Energy", 14, DEVICE_CLASS_POWER, None, ENERGY_KILO_WATT_HOUR, None ) sensor2.hass = hass sensor2.entity_id = "sensor.radio_energy" @@ -65,13 +65,19 @@ async def prometheus_client(hass, hass_client): await sensor2.async_update_ha_state() sensor3 = DemoSensor( - None, "Electricity price", 0.123, None, f"SEK/{ENERGY_KILO_WATT_HOUR}", None + None, + "Electricity price", + 0.123, + None, + None, + f"SEK/{ENERGY_KILO_WATT_HOUR}", + None, ) sensor3.hass = hass sensor3.entity_id = "sensor.electricity_price" await sensor3.async_update_ha_state() - sensor4 = DemoSensor(None, "Wind Direction", 25, None, DEGREE, None) + sensor4 = DemoSensor(None, "Wind Direction", 25, None, None, DEGREE, None) sensor4.hass = hass sensor4.entity_id = "sensor.wind_direction" await sensor4.async_update_ha_state() @@ -81,6 +87,7 @@ async def prometheus_client(hass, hass_client): "SPS30 PM <1µm Weight concentration", 3.7069, None, + None, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, None, )