Add input_button support to HomeKit (#62590)

This commit is contained in:
Franck Nijhof 2021-12-23 00:23:57 +01:00 committed by GitHub
parent cb82169e92
commit c5d62ccc7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 6 deletions

View File

@ -198,6 +198,7 @@ def get_accessory(hass, driver, state, aid, config): # noqa: C901
"automation", "automation",
"button", "button",
"input_boolean", "input_boolean",
"input_button",
"remote", "remote",
"scene", "scene",
"script", "script",

View File

@ -85,6 +85,7 @@ SUPPORTED_DOMAINS = [
"fan", "fan",
"humidifier", "humidifier",
"input_boolean", "input_boolean",
"input_button",
"input_select", "input_select",
"light", "light",
"lock", "lock",

View File

@ -12,7 +12,7 @@ from pyhap.const import (
CATEGORY_SWITCH, CATEGORY_SWITCH,
) )
from homeassistant.components import button from homeassistant.components import button, input_button
from homeassistant.components.input_select import ATTR_OPTIONS, SERVICE_SELECT_OPTION from homeassistant.components.input_select import ATTR_OPTIONS, SERVICE_SELECT_OPTION
from homeassistant.components.switch import DOMAIN from homeassistant.components.switch import DOMAIN
from homeassistant.components.vacuum import ( from homeassistant.components.vacuum import (
@ -70,7 +70,7 @@ VALVE_TYPE: dict[str, ValveInfo] = {
} }
ACTIVATE_ONLY_SWITCH_DOMAINS = {"button", "scene", "script"} ACTIVATE_ONLY_SWITCH_DOMAINS = {"button", "input_button", "scene", "script"}
ACTIVATE_ONLY_RESET_SECONDS = 10 ACTIVATE_ONLY_RESET_SECONDS = 10
@ -152,6 +152,8 @@ class Switch(HomeAccessory):
params = {} params = {}
elif self._domain == button.DOMAIN: elif self._domain == button.DOMAIN:
service = button.SERVICE_PRESS service = button.SERVICE_PRESS
elif self._domain == input_button.DOMAIN:
service = input_button.SERVICE_PRESS
else: else:
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF

View File

@ -272,6 +272,7 @@ def test_type_sensors(type_name, entity_id, state, attrs):
("Switch", "automation.test", "on", {}, {}), ("Switch", "automation.test", "on", {}, {}),
("Switch", "button.test", STATE_UNKNOWN, {}, {}), ("Switch", "button.test", STATE_UNKNOWN, {}, {}),
("Switch", "input_boolean.test", "on", {}, {}), ("Switch", "input_boolean.test", "on", {}, {}),
("Switch", "input_button.test", STATE_UNKNOWN, {}, {}),
("Switch", "remote.test", "on", {}, {}), ("Switch", "remote.test", "on", {}, {}),
("Switch", "scene.test", "on", {}, {}), ("Switch", "scene.test", "on", {}, {}),
("Switch", "script.test", "on", {}, {}), ("Switch", "script.test", "on", {}, {}),

View File

@ -451,10 +451,13 @@ async def test_input_select_switch(hass, hk_driver, events, domain):
assert acc.select_chars["option3"].value is False assert acc.select_chars["option3"].value is False
async def test_button_switch(hass, hk_driver, events): @pytest.mark.parametrize(
"""Test switch accessory from a button entity.""" "domain",
domain = "button" ["button", "input_button"],
entity_id = "button.test" )
async def test_button_switch(hass, hk_driver, events, domain):
"""Test switch accessory from a (input) button entity."""
entity_id = f"{domain}.test"
hass.states.async_set(entity_id, None) hass.states.async_set(entity_id, None)
await hass.async_block_till_done() await hass.async_block_till_done()