Add device automation support to binary_sensor entities (#26643)

* Add device automation support to binary_sensor entities

* turn_on -> turned_on

* Correct spelling of present

* Improve tests

* Fix strings

* Fix stale comment
This commit is contained in:
Erik Montnemery authored and Paulus Schoutsen committed 2019-09-22 11:13:17 -07:00
1 parent 14647f5391
commit e5f6f33340
4 files changed
+875

No files matched your search

@@ -0,0 +1,50 @@
"""
Provide a mock binary sensor platform.
Call init before using it in your tests to ensure clean test data.
"""
from homeassistant.components.binary_sensor import BinarySensorDevice, 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: MockBinarySensor(
name=f"{device_class} sensor",
is_on=True,
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 MockBinarySensor(MockEntity, BinarySensorDevice):
"""Mock Binary Sensor class."""
@property
def is_on(self):
"""Return true if the binary sensor is on."""
return self._handle("is_on")
@property
def device_class(self):
"""Return the class of this sensor."""
return self._handle("device_class")