uvjim / linksys_velop

Home Assistant integration for the Linksys Velop
MIT License
50 stars 7 forks source link

Task exception in the latest beta #463

Closed GSzabados closed 6 months ago

GSzabados commented 6 months ago

I see the following error message after activating the Mesh restart button. Might be due to some misconfiguration.

This error originated from a custom integration.

Logger: homeassistant
Source: custom_components/linksys_velop/select.py:50
integration: Linksys Velop (documentation, issues)
First occurred: 7 May 2024 at 19:08:58 (780 occurrences)
Last logged: 08:49:27

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 258, in _handle_refresh_interval
    await self._async_refresh(log_failures=True, scheduled=True)
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 414, in _async_refresh
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 168, in async_update_listeners
    update_callback()
  File "/config/custom_components/linksys_velop/__init__.py", line 867, in _handle_coordinator_update
    super()._handle_coordinator_update()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 492, in _handle_coordinator_update
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1009, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1071, in __async_calculate_state
    if extra_state_attributes := self.extra_state_attributes:
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/linksys_velop/select.py", line 182, in extra_state_attributes
    return self._additional_description.extra_attributes(**ea_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/linksys_velop/select.py", line 50, in _get_device_details
    if not device_name.startswith("Network Device (")
           ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'
GSzabados commented 6 months ago

I think started with this:

2024-05-07 19:07:55.798 ERROR (MainThread) [homeassistant.components.select] Error adding entity select.velop_mesh_devices for domain select with platform linksys_velop
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 580, in _async_add_entities
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 892, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1359, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1009, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1132, in _async_write_ha_state
    state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1071, in __async_calculate_state
    if extra_state_attributes := self.extra_state_attributes:
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/linksys_velop/select.py", line 182, in extra_state_attributes
    return self._additional_description.extra_attributes(**ea_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/linksys_velop/select.py", line 50, in _get_device_details
    if not device_name.startswith("Network Device (")
           ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'
uvjim commented 6 months ago

I can suppress this easily enough but it shouldn't ever really be an issue because there should always be a name for a device.

If you could send me the diagnostics from the integration that would help me track the root cause down.

GSzabados commented 6 months ago

I am quite sure it has to do something with the select.velop_mesh_devices as it is currently unavailable.

I just don't know in which configuration setting should I have it filled. Under the UI devices or the Device trackers, as I have selected in both of them none.

uvjim commented 6 months ago

I know exactly where the problem is, what I don't fully understand at the moment is why it is happening.

Essentially the library pulls the device name from the API. If there is no name, just like Linksys, the device will be labelled as 'Network Device'. This caused a problem in the select entity if there were multiple devices labelled as 'Network Device'. I applied a fix to an earlier beta that appended either the IP address, or the unique id if the device was disconnected. This made the item unique in the select and resolved the issue.

Now, this error implies that there is no name for the device, but that shouldn't be the case. So, your diagnostics will help me work out what was returned from the library and if I'm just missing a simple check somewhere or if there is something bigger at play.

The select entity only affects retrieving details for a device for either populating the attributes into the select or into the temporary UI device, depending on what your config is set to. Everything else in the integration should continue to work.

GSzabados commented 6 months ago

Do you have an email address where I can send you the diagnostics? Unfortunately it is far too big to send it through the Community Forum's messaging system. It is about 170000 character longer than the allowed maximum 32000. 😄

uvjim commented 6 months ago

Can you just compress it and attach the file?

GSzabados commented 6 months ago

config_entry-linksys_velop.zip

Use 7Zip to decompress it, I will message you the password.

GSzabados commented 6 months ago

Any chance you have an idea how this could be resolved?

uvjim commented 6 months ago

I haven't had time to have a look at it yet, I'm afraid.

uvjim commented 6 months ago

OK. I've had a quick look and still can't see why it's happening. Could you disable the select entity and see if the problem still happens?

Also, could you send me screenshots of the attributes for the Online Devices and Offline Devices attributes? It should detail the devices and their associated names which may shed some light for me.

GSzabados commented 6 months ago

I have disabled it and the error disappeared.

uvjim commented 6 months ago

OK, that's fine if you don't use it for anything (I'll make sure it's disabled by default). However, if you could send the screenshots I might be able to find what is actually causing the problem.

GSzabados commented 6 months ago

Sent you as a PM.

uvjim commented 6 months ago

Should be fixed by #470