HAP-python icon indicating copy to clipboard operation
HAP-python copied to clipboard

cannot find accessory.state

Open cactm08062 opened this issue 2 years ago • 3 comments

Exception has occurred: FileNotFoundError [WinError 2] The system cannot find the file specified: 'accessory.state' File "C:\Users\OWNER\homekit_test\HAP-python\pyhap\accessory_driver.py", line 648, in persist os.chmod(self.persist_file, 0o644) File "C:\Users\OWNER\homekit_test\HAP-python\pyhap\accessory_driver.py", line 483, in add_accessory self.persist() File "C:\Users\OWNER\homekit_test\HAP-python\main.py", line 57, in driver.add_accessory(accessory=get_accessory(driver)) FileNotFoundError: [WinError 2] The system cannot find the file specified: 'accessory.state'

cactm08062 avatar Feb 04 '23 19:02 cactm08062

The state-file will be created after the first homekit connection. It sounds like this process was never fulfilled.

Pythonaire avatar May 06 '23 07:05 Pythonaire

May I ask if you are experiencing this issue under the Windows operating system? I have also encountered this issue. I tried to add the following code in line 646 of "pyhap/accessory_driver. py" to solve this problem。

with open(self.persist_file, "w", encoding="utf8") as file_handle:
    self.encoder.persist(file_handle, self.state)

jiiiiiiiiiin avatar Aug 12 '23 06:08 jiiiiiiiiiin

On Windows os.chmod fails if the file doesn't exist; it's failing trying to make the current persistence file writable by the user, in preparation for swapping in the temporary file just written.

Fixed by #471

pjkundert avatar Apr 21 '24 18:04 pjkundert