mdeweerd / zha-toolkit

🧰 Zigbee Home Assistant Toolkit - service for "rare" Zigbee operations using ZHA on Home Assistant
GNU General Public License v3.0
171 stars 17 forks source link

[Errno 2] No such file or directory: '/config/scans/tmptphbmdk_' #192

Closed donburch888 closed 11 months ago

donburch888 commented 11 months ago

I'm setting up my zigbee mesh again from scratch, and trying to understand LQI, unavailablity and the Visualisation.

This was happening with Home Assistant 2023.7 and zha_toolkit version v0.9.7; and also now with HA 2023.8.

Calling zha_toolkit’s all_routes_and_neighbours but without data image results in two errors:

Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:420
First occurred: 11:03:10 AM (1 occurrences)
Last logged: 11:03:10 AM

websocket_api script: Error executing script. Error for call_service at pos 1: [Errno 2] No such file or directory: '/config/scans/tmptphbmdk_'

and

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:268
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 11:03:10 AM (1 occurrences)
Last logged: 11:03:10 AM

[139696716634304] Error handling message: [Errno 2] No such file or directory: '/config/scans/tmptphbmdk_' (unknown_error) don from 192.168.1.29 (Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0)

The section from the full log shows:

2023-08-04 11:03:10.379 DEBUG (MainThread) [custom_components.zha_toolkit.neighbours] NEIGHBORS: Neighbors(Entries=4, StartIndex=3, NeighborTableList=[Neighbor(extended_pan_id=5b:30:16:2c:38:05:2b:31, ieee=34:25:b4:ff:fe:d0:83:d0, nwk=0x582E, device_type=<DeviceType.Router: 1>, rx_on_when_idle=<RxOnWhenIdle.On: 1>, relationship=<Relationship.Parent: 0>, reserved1=0, permit_joining=<PermitJoins.Unknown: 2>, reserved2=0, depth=15, lqi=217)])
2023-08-04 11:03:10.379 DEBUG (MainThread) [custom_components.zha_toolkit.neighbours] 34:25:b4:ff:fe:bd:e3:f5: Got 5 out of 5
2023-08-04 11:03:10.380 ERROR (MainThread) [homeassistant.util.file] Saving file failed: /config/scans/all_routes_and_neighbours.json
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/util/file.py", line 59, in write_utf8_file
with tempfile.NamedTemporaryFile(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/tempfile.py", line 563, in NamedTemporaryFile
file = _io.open(dir, mode, buffering=buffering,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/tempfile.py", line 560, in opener
fd, name = _mkstemp_inner(dir, prefix, suffix, flags, output_type)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/tempfile.py", line 256, in _mkstemp_inner
fd = _os.open(file, flags, 0o600)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/config/scans/tmptphbmdk_'
2023-08-04 11:03:10.384 DEBUG (MainThread) [custom_components.zha_toolkit] event_data {'zha_toolkit_version': 'v0.9.7', 'zigpy_version': '0.56.2', 'zigpy_rf_version': '0.11.3', 'ieee_org': None, 'ieee': 'None', 'command': 'all_routes_and_neighbours', 'command_data': None, 'start_time': '2023-08-04T01:02:57.186708+00:00', 'errors': ["WriteError(FileNotFoundError(2, 'No such file or directory'))"], 'params': {'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'read_before_write': True, 'read_after_write': True}, 'result': {'00:12:4b:00:24:c2:74:d3': {'routes': [], 'neighbours': [{'pan_id': '5b:30:16:2c:38:05:2b:31', 'ieee': '00:12:4b:00:23:43:74:12', 'nwk': '0x0E2E', 'device_type': 'Router', 'rx_on_when_idle': 'Unknown', 'relationship': 'Sibling', 'permit_joining': 'Unknown', 'depth': 255, 'lqi': 41}, {'pan_id': '5b:30:16:2c:38:05:2b:31', 'ieee': '34:25:b4:ff:fe:bd:e3:f5', 'nwk': '0x9BE7', 'device_type': 'Router', 'rx_on_when_idle': 'Unknown', 
                       ... massive long message truncated ...
'5b:30:16:2c:38:05:2b:31', 'ieee': '34:25:b4:ff:fe:d0:83:d0', 'nwk': '0x582E', 'device_type': 'Router', 'rx_on_when_idle': 'On', 'relationship': 'Parent', 'permit_joining': 'Unknown', 'depth': 15, 'lqi': 217}, {'pan_id': '5b:30:16:2c:38:05:2b:31', 'ieee': 'f0:82:c0:ff:fe:fe:b6:7a', 'nwk': '0x0618', 'device_type': 'Router', 'rx_on_when_idle': 'On', 'relationship': 'Sibling', 'permit_joining': 'Unknown', 'depth': 15, 'lqi': 181}]}}, 'success': False}
2023-08-04 11:03:10.385 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Error for call_service at pos 1: [Errno 2] No such file or directory: '/config/scans/tmptphbmdk_'
2023-08-04 11:03:10.386 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139696716634304] Error handling message: [Errno 2] No such file or directory: '/config/scans/tmptphbmdk_' (unknown_error) don from 192.168.1.29 (Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0)
2023-08-04 11:03:11.952 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x582E](TRADFRI Signal Repeater): Device seen - marking the device available and resetting counter
2023-08-04 11:03:11.952 DEBUG (MainThread) [homeassistant.components.zha.core.device] [0x582E](TRADFRI Signal Repeater): Update device availability - device available: True - new availability: True - changed: False

The massively long DEBUG line between the error messages appears to contain all the network data, so I think the service call worked without any data parameters - it just didn't get saved to temp file, and so couldn't be displayed.

mdeweerd commented 11 months ago

Yes, the scan surely worked, but there is an issue with the write.

It is not clear how tempfile comes into play.

The '/config/scans' directory should be created if it is missing, you can check if it does, and if not create it manually. This is the code that normally does that:

https://github.com/mdeweerd/zha-toolkit/blob/ebcfaa3b9b1bdd3d153a9c66f4b7c382f2b30f64/custom_components/zha_toolkit/utils.py#L451-L452

I'll try to reproduce this later, but in the mean time you may be able to get some more info.

donburch888 commented 11 months ago

I looked with the File Editor add-on, and indeed there is no /config/scans directory - I have created it now. Curiously I see there is also a /config/csv directory (which I don't recall creating), containing /config/csv/test1.

Just tried all_routes_and_neighbours, but this time with the ieee of my coordinator ... and it takes a while but does display a result, so my issue is solved. Thank you.

Now to compare this result with the visualisation.

It is not clear how tempfile comes into play.

From the second error message including my PCs IP and browser type, my guess is that a generic component is used to display a JSON file in a human-readable format.

donburch888 commented 11 months ago

Oops, used the [Comment] instead of the [Close with comment] button. Thank you

mdeweerd commented 11 months ago

Good new. The csv directory is created with certain commands, normally when you define csvout in the parameters. This is available with the attr_read and attr_write commands for instance. I use it in some scripts to maintain a history of changes and values read (in a CSV file) and some other use cases.