Add support for restoring HomeKit IIDs (#79913)

This commit is contained in:
J. Nick Koston 2022-10-14 09:58:09 -10:00 committed by GitHub
parent 20f1f8aabb
commit 3b33e0d832
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 527 additions and 103 deletions

View file

@ -431,10 +431,15 @@ def get_persist_filename_for_entry_id(entry_id: str) -> str:
def get_aid_storage_filename_for_entry_id(entry_id: str) -> str:
"""Determine the ilename of homekit aid storage file."""
"""Determine the filename of homekit aid storage file."""
return f"{DOMAIN}.{entry_id}.aids"
def get_iid_storage_filename_for_entry_id(entry_id: str) -> str:
"""Determine the filename of homekit iid storage file."""
return f"{DOMAIN}.{entry_id}.iids"
def get_persist_fullpath_for_entry_id(hass: HomeAssistant, entry_id: str) -> str:
"""Determine the path to the homekit state file."""
return hass.config.path(STORAGE_DIR, get_persist_filename_for_entry_id(entry_id))
@ -447,6 +452,13 @@ def get_aid_storage_fullpath_for_entry_id(hass: HomeAssistant, entry_id: str) ->
)
def get_iid_storage_fullpath_for_entry_id(hass: HomeAssistant, entry_id: str) -> str:
"""Determine the path to the homekit iid storage file."""
return hass.config.path(
STORAGE_DIR, get_iid_storage_filename_for_entry_id(entry_id)
)
def _format_version_part(version_part: str) -> str:
return str(max(0, min(MAX_VERSION_PART, coerce_int(version_part))))
@ -466,14 +478,15 @@ def _is_zero_but_true(value: Any) -> bool:
return convert_to_float(value) == 0
def remove_state_files_for_entry_id(hass: HomeAssistant, entry_id: str) -> bool:
def remove_state_files_for_entry_id(hass: HomeAssistant, entry_id: str) -> None:
"""Remove the state files from disk."""
persist_file_path = get_persist_fullpath_for_entry_id(hass, entry_id)
aid_storage_path = get_aid_storage_fullpath_for_entry_id(hass, entry_id)
os.unlink(persist_file_path)
if os.path.exists(aid_storage_path):
os.unlink(aid_storage_path)
return True
for path in (
get_persist_fullpath_for_entry_id(hass, entry_id),
get_aid_storage_fullpath_for_entry_id(hass, entry_id),
get_iid_storage_fullpath_for_entry_id(hass, entry_id),
):
if os.path.exists(path):
os.unlink(path)
def _get_test_socket() -> socket.socket: