Vaskivskyi / ha-asusrouter

Monitor and control your AsusWRT-powered router from Home Assistant
https://asusrouter.vaskivskyi.com
Apache License 2.0
180 stars 17 forks source link

[Bug] Device internet access control - Unknown error #349

Closed tomas0620 closed 1 year ago

tomas0620 commented 1 year ago

The problem

All of the attempts to call service failed with an Unknown error. Calls:

  1. Direct call from Developer Tools -> Services
  2. Button for a device internet control (from Release Notes YAML example)
  3. Automations - (based on User comment from TekDad)

Your device model

RT-AC68U

Firmware type

Merlin

Firmware version

386.7_2

Integration version with the issue

0.12.1

Method of the integration installation

HACS

What version and type of Home Assistant installation do you use

2022.10.3 in docker

Is there anything useful in the logs?

Logger: homeassistant.helpers.script.websocket_api_script
Source: custom_components/asusrouter/bridge.py:624
Integration: AsusRouter (documentation, issues)
First occurred: 08:35:35 (1 occurrences)
Last logged: 08:35:35

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: None
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1738, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1775, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/asusrouter/router.py", line 423, in async_service_device_internet_access
    await self.bridge.async_device_internet_access(raw=service.data)
  File "/config/custom_components/asusrouter/bridge.py", line 624, in async_device_internet_access
    return await self.api.async_remove_parental_control_device(mac)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 942, in async_remove_parental_control_device
    request = compilers.parental_control(rules)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/util/compilers.py", line 143, in parental_control
    states += state_lib[data[rule].state] + ">"
KeyError: None

--------------------------------------------------------------------------------------------------------

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/asusrouter/bridge.py:624
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 08:35:35 (2 occurrences)
Last logged: 08:41:55

[140065635202528] Error handling message: Unknown error (unknown_error)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 648, in handle_execute_script
    await script_obj.async_run(msg.get("variables"), context=context)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1524, in async_run
    await asyncio.shield(run.async_run())
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 409, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 453, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1738, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1775, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/config/custom_components/asusrouter/router.py", line 423, in async_service_device_internet_access
    await self.bridge.async_device_internet_access(raw=service.data)
  File "/config/custom_components/asusrouter/bridge.py", line 624, in async_device_internet_access
    return await self.api.async_remove_parental_control_device(mac)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 942, in async_remove_parental_control_device
    request = compilers.parental_control(rules)
  File "/usr/local/lib/python3.10/site-packages/asusrouter/util/compilers.py", line 143, in parental_control
    states += state_lib[data[rule].state] + ">"
KeyError: None

Diagnostics information

No response

Additional information

No response

Vaskivskyi commented 1 year ago

Hey, @tomas0620,

Thanks for your feedback ๐Ÿ‘๐Ÿป and sorry that something does not work well for you.

Please, allow me 1-2 days to check out and fix the issue.

Meanwhile, can you please add the following info:

Answers to these questions will help to troubleshoot and fix the issue faster.

tomas0620 commented 1 year ago

Hi, thank you for your prompt reply.

The issue is happening for all types (block, remove, disable).

Log: Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/asusrouter/bridge.py:626 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 09:32:13 (1 occurrences) Last logged: 09:32:13

[140065591237296] Error handling message: Unknown error (unknown_error) Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response await func(hass, connection, msg) File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 648, in handle_execute_script await script_obj.async_run(msg.get("variables"), context=context) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1524, in async_run await asyncio.shield(run.async_run()) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 409, in async_run await self._async_step(log_exceptions=False) File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 453, in _async_step self._handle_exception( File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _handle_exception raise exception File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in _async_step await getattr(self, handler)() File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 684, in _async_call_service_step await service_task File "/usr/src/homeassistant/homeassistant/core.py", line 1738, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1775, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/config/custom_components/asusrouter/router.py", line 423, in async_service_device_internet_access await self.bridge.async_device_internet_access(raw=service.data) File "/config/custom_components/asusrouter/bridge.py", line 626, in async_device_internet_access return await self.api.async_set_parental_control_device(mac, name, state) File "/usr/local/lib/python3.10/site-packages/asusrouter/asusrouter.py", line 921, in async_set_parental_control_device request = compilers.parental_control(rules) File "/usr/local/lib/python3.10/site-packages/asusrouter/util/compilers.py", line 143, in parental_control states += state_lib[data[rule].state] + ">" KeyError: None

tomas0620 commented 1 year ago

Hi @Vaskivskyi

Can i add some more logs/informations for better investigation? Or somehow debug it locally?

THX

Vaskivskyi commented 1 year ago

Hey, sorry for the delay

tomas0620 commented 1 year ago

Hi,

this issue occurs only when there are no set parental control rules When I add one rule via router UI, the service in HA works without issues.

BUT! When I removed all rules, the problem was back.

Thus, there must be at least one rule set.

PS: parental control switch works without problems. No rules: parental_control_switch One rule: parental_control_switch_2

Vaskivskyi commented 1 year ago

Oh, I see. Great. This will help. I didn't manage yet to reproduce the issue, but I didn't think of trying without any rules set.

๐Ÿ‘๐Ÿป

Vaskivskyi commented 1 year ago

The issue should be fixed in the new version 0.13.0. Please, check it out

tomas0620 commented 1 year ago

Hi, Issue was fixed. Thanks a lot.