uvjim / linksys_velop

Home Assistant integration for the Linksys Velop
43 stars 6 forks source link

Parental control switch doesn’t work reliably #428

Closed dredjohn21 closed 1 year ago

dredjohn21 commented 1 year ago

Context: I have kids with laptops I have scheduled to pause internet access on at night. Sometimes we want to cut access sooner (e.g. punishment), or enable later (e.g. finish homework).

I’m noticing with this integration when I add the devices to UI so I can easily enable/disable internet access via switch.chromebook_child1_internet_access the switch will not update properly (it’ll show as off but still on, or visa versa).

I tried to enable logging with query and captured this:

Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/linksys_velop/switch.py:301 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 6:20:02 AM (1 occurrences) Last logged: 6:20:02 AM

[547767923344] list index out of range Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service await hass.services.async_call( File "/usr/src/homeassistant/homeassistant/core.py", line 1910, in async_call task.result() File "/usr/src/homeassistant/homeassistant/core.py", line 1950, in _execute_service await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)( File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 226, in handle_service await service.entity_service_call( File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 811, in entity_service_call future.result() # pop exception if have ^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1034, in async_request_call await coro File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 851, in _handle_entity_call await result File "/config/custom_components/linksys_velop/switch.py", line 301, in async_turn_on await action(**action_args) File "/usr/local/lib/python3.11/site-packages/pyvelop/mesh.py", line 985, in async_set_parental_control_rules if this_device_rules[0].get("blockedURLs", []):


IndexError: list index out of range
dredjohn21 commented 1 year ago

I suspect it has something to do with the switch seeing the device as having internet OFF when it’s just on a schedule.

for example devices without schedules seem to be working ok (maybe that is how I work around this and put the scheduling in home assistant?)

uvjim commented 1 year ago

Just so I have this clear...

You have a UI device and are using the switch entity that belongs to that device?

Can you confirm if the switch changes state after the integration has polled again?

I spotted the trace that you listed but I'm not sure how your scenario should get to that line.

uvjim commented 1 year ago

Oh and can you confirm does the device have rules assigned to it when you change the switch state?

dredjohn21 commented 1 year ago

Hi @uvjim yes your understanding is correct:

if it’s easier maybe I just disable the Linksys Velop rules and build my own in home assistant? Is that how you are managing on your side?

uvjim commented 1 year ago

Oh I don't use any of that functionality at all. I only built it in because I could. 😂

I have one device that I deny access to the Internet at all times until I decide to update it but that's it.

I'll try and have a look at it soon. The trace shows an issue in the library (I wrote that too) and I'm not sure how you've reached that line. However, I'll see if I can recreate the issue, I have plenty of devices on the network I can mess around with and not cause a problem.

Leave it with me.

dredjohn21 commented 1 year ago

Ha - you’re so awesome - thank you!! :)

uvjim commented 1 year ago

I don't seem to be able to recreate the issue. However, the code isn't quite working correctly. The switch should only show off if Internet is paused for the device, at all other times it will show as on. That doesn't seem to be the case with the way things are at the moment - bizarre because I could have sworn I tested that. Oh well. I'll take a look at what's going on in more details when I get time. I think once that is fixed you'll be able to achieve what you want, i.e.

dredjohn21 commented 1 year ago

Thanks so much - all of that would be amazing (kids are on warning 🤪)

uvjim commented 1 year ago

I've pushed beta version 2023.7.1b0 can you try that and see how you get on please?

dredjohn21 commented 1 year ago

Thanks I just tried it

My observations:

  1. The enable/disable internet switches didn’t seem to pause/resume internet access. I had 4 devices setup for parental controls. 2 of them had scheduled time off (later at night; wasn’t in the window yet). I could enable or disable in home assistant and there was no change in the Linksys parental control setting.
  2. When I enabled detailed logging with the query response I started getting error messages whenever I enabled or disabled within home assistant:
Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/linksys_velop/switch.py:301 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 8:16:03 PM (1 occurrences) 
Last logged: 8:16:03 PM

[547125638160] list index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1910, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1950, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 226, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 811, in entity_service_call
    future.result()  # pop exception if have
    ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1034, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 851, in _handle_entity_call
    await result
  File "/config/custom_components/linksys_velop/switch.py", line 301, in async_turn_on
    await action(**action_args)
  File "/usr/local/lib/python3.11/site-packages/pyvelop/mesh.py", line 985, in async_set_parental_control_rules
    if this_device_rules[0].get("blockedURLs", []):
       ~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range
uvjim commented 1 year ago

2023.7.1b1 is now available. Could you test that please?

RE: your observations...

  1. The Linksys app doesn't respond very well to changes that it didn't initiate. The best thing you can do is re-open the app after each change you make (a full re-open, if it just comes back from the background it still doesn't update very well).
  2. I've put a guard in to check against this one in the library so you shouldn't see this error now.

I have tested multiple scenarios both directly in the library and in Home Assistant. Each time it is doing what I expect. Example...

  1. Device has a schedule (the Blocked Times sensor should be set to "yes" with attributes set to schedule times and the switch is "on")
  2. Turn the switch off (the Blocked Times sensor should be set to "yes" with attributes set to "00:00-00:00" for all days and the switch is "off")
  3. Turn the switch on (the Blocked Times sensor should be set to "yes" with the attributes set to the previous schedule and the switch is "on")

I've also tested using the Home Assistant services and they all update as expected, albeit on the poll period.

dredjohn21 commented 1 year ago

Yay works perfectly! The only issue is the one you noted: the Linksys app doesn’t quickly reflect the change. I waited a minute in one case, going back and forth between screens in the mobile app hoping it would refresh and it didn’t… so I eventually killed the app and reloaded and everything showed correctly. But this is out of your control… thanks so much for all this extra effort. Hopefully others will also benefit from this additional level of control (especially helpful with kids!)