Add homekit_controller service.sensor.smoke (#30269)

This commit is contained in:
Jc2k authored and GitHub committed 2019-12-30 08:05:49 +00:00
1 parent 8a22a38353
commit fccb13b762
3 files changed
+63 -2

No files matched your search

@@ -3,6 +3,7 @@ from tests.components.homekit_controller.common import FakeService, setup_test_c
MOTION_DETECTED = ("motion", "motion-detected")
CONTACT_STATE = ("contact", "contact-state")
SMOKE_DETECTED = ("smoke", "smoke-detected")
def create_motion_sensor_service():
@@ -51,3 +52,29 @@ async def test_contact_sensor_read_state(hass, utcnow):
helper.characteristics[CONTACT_STATE].value = 1
state = await helper.poll_and_get_state()
assert state.state == "on"
def create_smoke_sensor_service():
"""Define smoke sensor characteristics."""
service = FakeService("public.hap.service.sensor.smoke")
cur_state = service.add_characteristic("smoke-detected")
cur_state.value = 0
return service
async def test_smoke_sensor_read_state(hass, utcnow):
"""Test that we can read the state of a HomeKit contact accessory."""
sensor = create_smoke_sensor_service()
helper = await setup_test_component(hass, [sensor])
helper.characteristics[SMOKE_DETECTED].value = 0
state = await helper.poll_and_get_state()
assert state.state == "off"
helper.characteristics[SMOKE_DETECTED].value = 1
state = await helper.poll_and_get_state()
assert state.state == "on"
assert state.attributes["device_class"] == "smoke"