Add scenes as switches HomeKit (#17799)

This commit is contained in:
quthla 2018-11-05 21:36:30 +01:00 committed by cdce8p
parent 93b16e7efb
commit c59b038512
4 changed files with 6 additions and 1 deletions

View File

@ -170,7 +170,8 @@ def get_accessory(hass, driver, state, aid, config):
switch_type = config.get(CONF_TYPE, TYPE_SWITCH)
a_type = SWITCH_TYPES[switch_type]
elif state.domain in ('automation', 'input_boolean', 'remote', 'script'):
elif state.domain in ('automation', 'input_boolean', 'remote', 'scene',
'script'):
a_type = 'Switch'
elif state.domain == 'water_heater':

View File

@ -86,6 +86,8 @@ class Switch(HomeAccessory):
def is_activate(self, state):
"""Check if entity is activate only."""
can_cancel = state.attributes.get(ATTR_CAN_CANCEL)
if self._domain == 'scene':
return True
if self._domain == 'script' and not can_cancel:
return True
return False

View File

@ -139,6 +139,7 @@ def test_type_sensors(type_name, entity_id, state, attrs):
('Switch', 'automation.test', 'on', {}, {}),
('Switch', 'input_boolean.test', 'on', {}, {}),
('Switch', 'remote.test', 'on', {}, {}),
('Switch', 'scene.test', 'on', {}, {}),
('Switch', 'script.test', 'on', {}, {}),
('Switch', 'switch.test', 'on', {}, {}),
('Switch', 'switch.test', 'on', {}, {CONF_TYPE: TYPE_SWITCH}),

View File

@ -180,6 +180,7 @@ async def test_valve_set_state(hass, hk_driver, events):
@pytest.mark.parametrize('entity_id, attrs', [
('scene.test', {}),
('script.test', {}),
('script.test', {ATTR_CAN_CANCEL: False}),
])