HASwitchPlate / openHASP-custom-component

Home Assistant custom component for openHASP
https://www.openhasp.com
MIT License
49 stars 9 forks source link

'str' object has no attribute 'read' #131

Open illuzn opened 5 days ago

illuzn commented 5 days ago

Version of the custom_component

0.7.3

Configuration

yaml not relevant.

OpenHASP is configured to send a json file (not jsonl). The json file is correctly formatted and is in HA's allowed external directories.

Describe the bug

The following handler fails to load the json file correctly. https://github.com/HASwitchPlate/openHASP-custom-component/blob/24f071cb510f3da0e5c801ccd52eb5abad9c4d6b/custom_components/openhasp/__init__.py#L656-L667

json.load expects a file object but it appears to be receiving a string instead.

Debug log


2024-07-03 18:51:51.891 ERROR (MainThread) [homeassistant.util.logging] Exception in lwt_message_received when handling msg on 'hasp/hallway_panel/LWT': 'online'
Traceback (most recent call last):
File "/config/custom_components/openhasp/__init__.py", line 479, in lwt_message_received
await self.async_load_page(self._pages_jsonl)
File "/config/custom_components/openhasp/__init__.py", line 658, in async_load_page
json_data = json.load(pages_file)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/json/__init__.py", line 293, in load
return loads(fp.read(),
^^^^^^^
AttributeError: 'str' object has no attribute 'read'
Woutch commented 4 days ago

I have the same problem, rollback to 0.7.2 worked for now.

fvanroie commented 4 days ago

dgomes I believe it should be either

     json_data = json.loads(pages_file) 

or

     json_data = json.load(path) 
dgomes commented 4 days ago

Yes that's the solution, but need to validate