Add homekit_controller occupancy sensor (#32188)

This commit is contained in:
Jc2k authored and GitHub committed 2020-02-25 22:01:03 +00:00
1 parent dd13e99967
commit 4a89fba6f9
5 files changed
+327

No files matched your search

@@ -0,0 +1,37 @@
"""
Regression tests for Ecobee occupancy.
https://github.com/home-assistant/home-assistant/issues/31827
"""
from tests.components.homekit_controller.common import (
Helper,
setup_accessories_from_file,
setup_test_accessories,
)
async def test_ecobee_occupancy_setup(hass):
"""Test that an Ecbobee occupancy sensor be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, "ecobee_occupancy.json")
config_entry, pairing = await setup_test_accessories(hass, accessories)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
sensor = entity_registry.async_get("binary_sensor.master_fan")
assert sensor.unique_id == "homekit-111111111111-56"
sensor_helper = Helper(
hass, "binary_sensor.master_fan", pairing, accessories[0], config_entry
)
sensor_state = await sensor_helper.poll_and_get_state()
assert sensor_state.attributes["friendly_name"] == "Master Fan"
device_registry = await hass.helpers.device_registry.async_get_registry()
device = device_registry.async_get(sensor.device_id)
assert device.manufacturer == "ecobee Inc."
assert device.name == "Master Fan"
assert device.model == "ecobee Switch+"
assert device.sw_version == "4.5.130201"
assert device.via_device_id is None
@@ -4,6 +4,7 @@ from aiohomekit.model.services import ServicesTypes
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OCCUPANCY,
DEVICE_CLASS_OPENING,
DEVICE_CLASS_SMOKE,
)
@@ -13,6 +14,7 @@ from tests.components.homekit_controller.common import setup_test_component
MOTION_DETECTED = ("motion", "motion-detected")
CONTACT_STATE = ("contact", "contact-state")
SMOKE_DETECTED = ("smoke", "smoke-detected")
OCCUPANCY_DETECTED = ("occupancy", "occupancy-detected")
def create_motion_sensor_service(accessory):
@@ -82,3 +84,26 @@ async def test_smoke_sensor_read_state(hass, utcnow):
assert state.state == "on"
assert state.attributes["device_class"] == DEVICE_CLASS_SMOKE
def create_occupancy_sensor_service(accessory):
"""Define occupancy characteristics."""
service = accessory.add_service(ServicesTypes.OCCUPANCY_SENSOR)
cur_state = service.add_char(CharacteristicsTypes.OCCUPANCY_DETECTED)
cur_state.value = 0
async def test_occupancy_sensor_read_state(hass, utcnow):
"""Test that we can read the state of a HomeKit occupancy sensor accessory."""
helper = await setup_test_component(hass, create_occupancy_sensor_service)
helper.characteristics[OCCUPANCY_DETECTED].value = False
state = await helper.poll_and_get_state()
assert state.state == "off"
helper.characteristics[OCCUPANCY_DETECTED].value = True
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["device_class"] == DEVICE_CLASS_OCCUPANCY