1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add device trigger support to sensor entities (#27133)

* Add device trigger support to sensor entities

* Fix typing

* Fix tests, add test helper for comparing lists
This commit is contained in:
Erik Montnemery
2019-10-03 06:14:35 +02:00
committed by GitHub
parent e005f6f23a
commit 3e99743244
10 changed files with 689 additions and 11 deletions

View File

@@ -0,0 +1,44 @@
"""
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
from tests.common import MockEntity
ENTITIES = {}
def init(empty=False):
"""Initialize the platform with entities."""
global ENTITIES
ENTITIES = (
{}
if empty
else {
device_class: MockSensor(
name=f"{device_class} sensor",
unique_id=f"unique_{device_class}",
device_class=device_class,
)
for device_class in DEVICE_CLASSES
}
)
async def async_setup_platform(
hass, config, async_add_entities_callback, discovery_info=None
):
"""Return mock entities."""
async_add_entities_callback(list(ENTITIES.values()))
class MockSensor(MockEntity):
"""Mock Sensor class."""
@property
def device_class(self):
"""Return the class of this sensor."""
return self._handle("device_class")