Skip to content

Error adding new device (object has no attribute '_cli') #57

Description

@DaveFace

Per issue 46 on the hassio-ftms integration, there is an error from the python-pyftms library when connecting to some new devices:

Traceback (most recent call last):
  File "src/dbus_fast/message_bus.py", line 819, in dbus_fast.message_bus.BaseMessageBus._process_message
  File "/usr/local/lib/python3.14/site-packages/bleak/backends/bluezdbus/manager.py", line 1121, in _parse_msg
    watcher.on_connected_changed(new_connected)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/bleak/backends/bluezdbus/client.py", line 173, in on_connected_changed
    self._disconnected_callback()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.14/site-packages/pyftms/client/client.py", line 226, in _on_disconnect
    del self._cli
        ^^^^^^^^^
AttributeError: 'Treadmill' object has no attribute '_cli'

Which in the current version tracks to line 245, or this function:

def _on_disconnect(self, cli: BleakClient) -> None:
    _LOGGER.debug("Client disconnected. Reset updaters states.")

    del self._cli
    self._updater.reset()
    self._controller.reset()

    if self._disconnect_cb:
        self._disconnect_cb(self)

And it seems to be a race condition with the self._cli attribute not being created by the _connect function. Adding a check for it seemed to resolve the issue and the integration worked:

if hasattr(self, "_cli"):
    del self._cli

But I'm not sure this is the best approach - honestly, deleting attributes on the class always seems a bit icky to me so it seems like this part should be refactored.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions