1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-02 22:52:06 +01:00

Only generate device trigger for sensor with unit (#27152)

This commit is contained in:
Erik Montnemery
2019-10-03 22:30:59 +02:00
committed by Paulus Schoutsen
parent cda7692f24
commit 89ebc17fb1
3 changed files with 33 additions and 4 deletions

View File

@@ -3,10 +3,24 @@ Provide a mock sensor platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.components.sensor import DEVICE_CLASSES
import homeassistant.components.sensor as sensor
from tests.common import MockEntity
DEVICE_CLASSES = list(sensor.DEVICE_CLASSES)
DEVICE_CLASSES.append("none")
UNITS_OF_MEASUREMENT = {
sensor.DEVICE_CLASS_BATTERY: "%", # % of battery that is left
sensor.DEVICE_CLASS_HUMIDITY: "%", # % of humidity in the air
sensor.DEVICE_CLASS_ILLUMINANCE: "lm", # current light level (lx/lm)
sensor.DEVICE_CLASS_SIGNAL_STRENGTH: "dB", # signal strength (dB/dBm)
sensor.DEVICE_CLASS_TEMPERATURE: "C", # temperature (C/F)
sensor.DEVICE_CLASS_TIMESTAMP: "hh:mm:ss", # timestamp (ISO8601)
sensor.DEVICE_CLASS_PRESSURE: "hPa", # pressure (hPa/mbar)
sensor.DEVICE_CLASS_POWER: "kW", # power (W/kW)
}
ENTITIES = {}
@@ -22,6 +36,7 @@ def init(empty=False):
name=f"{device_class} sensor",
unique_id=f"unique_{device_class}",
device_class=device_class,
unit_of_measurement=UNITS_OF_MEASUREMENT.get(device_class),
)
for device_class in DEVICE_CLASSES
}
@@ -42,3 +57,8 @@ class MockSensor(MockEntity):
def device_class(self):
"""Return the class of this sensor."""
return self._handle("device_class")
@property
def unit_of_measurement(self):
"""Return the unit_of_measurement of this sensor."""
return self._handle("unit_of_measurement")