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

This commit is contained in:
Erik Montnemery authored and Paulus Schoutsen committed 2019-10-03 13:30:59 -07:00
1 parent cda7692f24
commit 89ebc17fb1
3 files changed
+33 -4

No files matched your search

@@ -2,7 +2,7 @@
from datetime import timedelta
import pytest
from homeassistant.components.sensor import DOMAIN, DEVICE_CLASSES
from homeassistant.components.sensor import DOMAIN
from homeassistant.components.sensor.device_trigger import ENTITY_TRIGGERS
from homeassistant.const import STATE_UNKNOWN, CONF_PLATFORM
from homeassistant.setup import async_setup_component
@@ -19,6 +19,7 @@ from tests.common import (
async_get_device_automations,
async_get_device_automation_capabilities,
)
from tests.testing_config.custom_components.test.sensor import DEVICE_CLASSES
@pytest.fixture
@@ -70,6 +71,7 @@ async def test_get_triggers(hass, device_reg, entity_reg):
}
for device_class in DEVICE_CLASSES
for trigger in ENTITY_TRIGGERS[device_class]
if device_class != "none"
]
triggers = await async_get_device_automations(hass, "trigger", device_entry.id)
assert triggers == expected_triggers
@@ -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")