Device automation triggers for stateless HomeKit accessories (#39090)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Jc2k 2020-09-11 19:34:07 +01:00 committed by GitHub
parent 741487a1fc
commit 988a467afd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 915 additions and 4 deletions

View file

@ -0,0 +1,52 @@
"""
Regression tests for Aqara AR004.
This device has a non-standard programmable stateless switch service that has a
service-label-index despite not being linked to a service-label.
https://github.com/home-assistant/core/pull/39090
"""
from tests.common import assert_lists_same, async_get_device_automations
from tests.components.homekit_controller.common import (
setup_accessories_from_file,
setup_test_accessories,
)
async def test_aqara_switch_setup(hass):
"""Test that a Aqara Switch can be correctly setup in HA."""
accessories = await setup_accessories_from_file(hass, "aqara_switch.json")
config_entry, pairing = await setup_test_accessories(hass, accessories)
entity_registry = await hass.helpers.entity_registry.async_get_registry()
battery_id = "sensor.programmable_switch_battery"
battery = entity_registry.async_get(battery_id)
assert battery.unique_id == "homekit-111a1111a1a111-5"
# The fixture file has 1 button and a battery
expected = [
{
"device_id": battery.device_id,
"domain": "sensor",
"entity_id": "sensor.programmable_switch_battery",
"platform": "device",
"type": "battery_level",
}
]
for subtype in ("single_press", "double_press", "long_press"):
expected.append(
{
"device_id": battery.device_id,
"domain": "homekit_controller",
"platform": "device",
"type": "button1",
"subtype": subtype,
}
)
triggers = await async_get_device_automations(hass, "trigger", battery.device_id)
assert_lists_same(triggers, expected)

View file

@ -1,5 +1,6 @@
"""Tests for handling accessories on a Hue bridge via HomeKit."""
from tests.common import assert_lists_same, async_get_device_automations
from tests.components.homekit_controller.common import (
Helper,
setup_accessories_from_file,
@ -34,3 +35,32 @@ async def test_hue_bridge_setup(hass):
assert device.name == "Hue dimmer switch"
assert device.model == "RWL021"
assert device.sw_version == "45.1.17846"
# The fixture file has 1 dimmer, which is a remote with 4 buttons
# It (incorrectly) claims to support single, double and long press events
# It also has a battery
expected = [
{
"device_id": device.id,
"domain": "sensor",
"entity_id": "sensor.hue_dimmer_switch_battery",
"platform": "device",
"type": "battery_level",
}
]
for button in ("button1", "button2", "button3", "button4"):
for subtype in ("single_press", "double_press", "long_press"):
expected.append(
{
"device_id": device.id,
"domain": "homekit_controller",
"platform": "device",
"type": button,
"subtype": subtype,
}
)
triggers = await async_get_device_automations(hass, "trigger", device.id)
assert_lists_same(triggers, expected)

View file

@ -1,12 +1,12 @@
"""Make sure that handling real world LG HomeKit characteristics isn't broken."""
from homeassistant.components.media_player.const import (
SUPPORT_PAUSE,
SUPPORT_PLAY,
SUPPORT_SELECT_SOURCE,
)
from tests.common import async_get_device_automations
from tests.components.homekit_controller.common import (
Helper,
setup_accessories_from_file,
@ -62,3 +62,7 @@ async def test_lg_tv(hass):
assert device.model == "OLED55B9PUA"
assert device.sw_version == "04.71.04"
assert device.via_device_id is None
# A TV doesn't have any triggers
triggers = await async_get_device_automations(hass, "trigger", device.id)
assert triggers == []