Fix homekit locks not being created from when setup from the UI (#53301)

pull/53305/head
J. Nick Koston 2021-07-21 19:22:06 -10:00 committed by Paulus Schoutsen
parent bffef87103
commit 464986921e
5 changed files with 16 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import voluptuous as vol
from homeassistant import config_entries
from homeassistant.components.camera import DOMAIN as CAMERA_DOMAIN
from homeassistant.components.lock import DOMAIN as LOCK_DOMAIN
from homeassistant.components.media_player import DOMAIN as MEDIA_PLAYER_DOMAIN
from homeassistant.components.remote import DOMAIN as REMOTE_DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT
@ -54,7 +55,12 @@ MODE_EXCLUDE = "exclude"
INCLUDE_EXCLUDE_MODES = [MODE_EXCLUDE, MODE_INCLUDE]
DOMAINS_NEED_ACCESSORY_MODE = [CAMERA_DOMAIN, MEDIA_PLAYER_DOMAIN, REMOTE_DOMAIN]
DOMAINS_NEED_ACCESSORY_MODE = [
CAMERA_DOMAIN,
LOCK_DOMAIN,
MEDIA_PLAYER_DOMAIN,
REMOTE_DOMAIN,
]
NEVER_BRIDGED_DOMAINS = [CAMERA_DOMAIN]
CAMERA_ENTITY_PREFIX = f"{CAMERA_DOMAIN}."

View File

@ -43,7 +43,7 @@
"data": {
"include_domains": "Domains to include"
},
"description": "Choose the domains to be included. All supported entities in the domain will be included. A separate HomeKit instance in accessory mode will be created for each tv media player and camera.",
"description": "Choose the domains to be included. All supported entities in the domain will be included. A separate HomeKit instance in accessory mode will be created for each tv media player, activity based remote, lock, and camera.",
"title": "Select domains to be included"
},
"pairing": {

View File

@ -12,7 +12,7 @@
"data": {
"include_domains": "Domains to include"
},
"description": "Choose the domains to be included. All supported entities in the domain will be included. A separate HomeKit instance in accessory mode will be created for each tv media player and camera.",
"description": "Choose the domains to be included. All supported entities in the domain will be included. A separate HomeKit instance in accessory mode will be created for each tv media player, activity based remote, lock, and camera.",
"title": "Select domains to be included"
}
}

View File

@ -499,12 +499,11 @@ def accessory_friendly_name(hass_name, accessory):
def state_needs_accessory_mode(state):
"""Return if the entity represented by the state must be paired in accessory mode."""
if state.domain == CAMERA_DOMAIN:
if state.domain in (CAMERA_DOMAIN, LOCK_DOMAIN):
return True
return (
state.domain == LOCK_DOMAIN
or state.domain == MEDIA_PLAYER_DOMAIN
state.domain == MEDIA_PLAYER_DOMAIN
and state.attributes.get(ATTR_DEVICE_CLASS) == DEVICE_CLASS_TV
or state.domain == REMOTE_DOMAIN
and state.attributes.get(ATTR_SUPPORTED_FEATURES, 0) & SUPPORT_ACTIVITY

View File

@ -144,6 +144,7 @@ async def test_setup_creates_entries_for_accessory_mode_devices(hass):
"""Test we can setup a new instance and we create entries for accessory mode devices."""
hass.states.async_set("camera.one", "on")
hass.states.async_set("camera.existing", "on")
hass.states.async_set("lock.new", "on")
hass.states.async_set("media_player.two", "on", {"device_class": "tv"})
hass.states.async_set("remote.standard", "on")
hass.states.async_set("remote.activity", "on", {"supported_features": 4})
@ -180,7 +181,7 @@ async def test_setup_creates_entries_for_accessory_mode_devices(hass):
result2 = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"include_domains": ["camera", "media_player", "light", "remote"]},
{"include_domains": ["camera", "media_player", "light", "lock", "remote"]},
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["step_id"] == "pairing"
@ -207,7 +208,7 @@ async def test_setup_creates_entries_for_accessory_mode_devices(hass):
"filter": {
"exclude_domains": [],
"exclude_entities": [],
"include_domains": ["media_player", "light", "remote"],
"include_domains": ["media_player", "light", "lock", "remote"],
"include_entities": [],
},
"exclude_accessory_mode": True,
@ -225,7 +226,8 @@ async def test_setup_creates_entries_for_accessory_mode_devices(hass):
# 4 - camera.one in accessory mode
# 5 - media_player.two in accessory mode
# 6 - remote.activity in accessory mode
assert len(mock_setup_entry.mock_calls) == 6
# 7 - lock.new in accessory mode
assert len(mock_setup_entry.mock_calls) == 7
async def test_import(hass):