mdeweerd / zha-toolkit

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

Unexpected error for call_service at pos 1: 'NoneType' object has no attribute 'bus' #258

Open rofo69 opened 3 months ago

rofo69 commented 3 months ago

I'm getting the following in the logs when calling zha_toolkit.zha_devices:-

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/zha_toolkit/__init__.py", line 817, in toolkit_service
    u.get_hass(zha_gw).bus.fire(params[p.EVT_DONE], event_data)
    ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'bus'

Currently running v1.1.19

And also now:-

Exception ''ZHAGatewayProxy' object has no attribute 'devices'' for service call with data '{'zha_toolkit_version': 'v1.1.19', 'zigpy_version': '0.65.3', 'zigpy_rf_version': '0.40.3', 'ieee_org': None, 'ieee': 'None', 'command': 'zha_devices', 'command_data': None, 'start_time': '2024-08-15T07:48:36.700538+00:00', 'errors': ['AttributeError("\'ZHAGatewayProxy\' object has no attribute \'devices\'")'], 'params': {'dir': 0, 'tries': 1, 'expect_reply': True, 'args': [], 'read_before_write': True, 'read_after_write': True}, 'success': False}'

mdeweerd commented 3 months ago

Running on 2024.8.1 or older ? (2024.8.0 introduced a lot of changes in zha).

EDIT: I suppose that you are on 2024.8. It looks like there is an issue with zha_toolkit::utils::get_hass() which returns None. Which means that zha_gw is "None" or hass was not properly retrieved from zha_gw.

rofo69 commented 3 months ago

I'm running 2024.8.1

mdeweerd commented 3 months ago

I've added 1.1.20 as a beta/pre-release. I should log information about the properties available from the gateway to see which one we can use.

yuejon commented 3 months ago

I'm getting the same error with 1.1.19 and I just tried 1.1.20 but it's now throwing a different error:

Logger: homeassistant.components.script.poll_zigbee_routers
Source: helpers/script.py:525
integration: Script (documentation, issues)
First occurred: 1:31:21 PM (2 occurrences)
Last logged: 1:31:21 PM

Poll Zigbee Routers: Mudroom Light: Error executing script. Unexpected error for call_service at pos 1: Could not get hass from <zha.application.gateway.Gateway object at 0x7f3d4b9946b0>.Attributes available {dir(gateway)}.
Poll Zigbee Routers: Error executing script. Unexpected error for if at pos 1: Could not get hass from <zha.application.gateway.Gateway object at 0x7f3d4b9946b0>.Attributes available {dir(gateway)}.
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 525, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 764, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 727, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2763, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2806, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/zha_toolkit/__init__.py", line 809, in toolkit_service
    u.get_hass(zha_gw).bus.fire(params[p.EVT_SUCCESS], event_data)
    ^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/zha_toolkit/utils.py", line 1190, in get_hass
    raise ValueError(msg)
ValueError: Could not get hass from <zha.application.gateway.Gateway object at 0x7f3d4b9946b0>.Attributes available {dir(gateway)}.

I'm currently on 2024.8.2

mdeweerd commented 3 months ago

I made another pre-release which should provide more info in Attributes available {dir(gateway)}..

yuejon commented 3 months ago

I figured out that if I put the actual name of the attribute (i.e. last_message_rssi) instead of the attribute id (i.e. 285), it works again.

terba commented 3 months ago

I get the same error when the answer to zha_toolkit.conf_report_read arrives. v1.1.19 on 2024.8.3

mikehosmar commented 3 months ago

Same issue running the znp backup.

v1.1.19 on 2024.8.3

DevSecNinja commented 2 months ago

Same issue running the znp backup.

v1.1.19 on 2024.8.3

Same issue for me with the backup automation on 2024.9.1.