Add support for restoring HomeKit IIDs (#79913)
This commit is contained in:
parent
20f1f8aabb
commit
3b33e0d832
23 changed files with 527 additions and 103 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue