Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluetooth Manager Callback error MotionDirection #108087

Closed
c0nt4x opened this issue Jan 15, 2024 · 15 comments
Closed

Bluetooth Manager Callback error MotionDirection #108087

c0nt4x opened this issue Jan 15, 2024 · 15 comments

Comments

@c0nt4x
Copy link

c0nt4x commented Jan 15, 2024

The problem

Had this error in the logs a numerous times over the last few days

What version of Home Assistant Core has the issue?

2024.1.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/bluetooth

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.bluetooth.manager
Source: components/bluetooth/manager.py:109
Integration: Bluetooth (documentation, issues)
First occurred: 11:57:01 AM (1 occurrences)
Last logged: 11:57:01 AM

Error in bluetooth callback
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/manager.py", line 109, in _discover_service_info
    callback(service_info, BluetoothChange.ADVERTISEMENT)
  File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 114, in _async_handle_bluetooth_event
    super()._async_handle_bluetooth_event(service_info, change)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/active_update_coordinator.py", line 163, in _async_handle_bluetooth_event
    super()._async_handle_bluetooth_event(service_info, change)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_coordinator.py", line 89, in _async_handle_bluetooth_event
    self.async_update_listeners()
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_coordinator.py", line 51, in async_update_listeners
    update_callback()
  File "/usr/src/homeassistant/homeassistant/components/switchbot/cover.py", line 188, in _handle_coordinator_update
    self._attr_is_opening = self.parsed_data["motionDirection"]["opening"]
                            ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'motionDirection'

Additional information

No response

@home-assistant
Copy link

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (bluetooth) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of bluetooth can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign bluetooth Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


bluetooth documentation
bluetooth source
(message by IssueLinks)

@home-assistant
Copy link

Hey there @Danielhiversen, @RenierM26, @murtas, @Eloston, @dsypniewski, mind taking a look at this issue as it has been labeled with an integration (switchbot) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of switchbot can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign switchbot Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


switchbot documentation
switchbot source
(message by IssueLinks)

@joostlek
Copy link
Member

(maybe cc @dcmeglio because you checked out something with this that's in the next release)

@dcmeglio
Copy link
Contributor

This looks like code for the blind tilt device, I was working on the Curtain device. Unfortunately I don't have a Tilt to test with.

@joostlek
Copy link
Member

Does it maybe look familiar to the curtain way of working? Could there be a moment where we could not get the position of the device?

@dcmeglio
Copy link
Contributor

dcmeglio commented Jan 15, 2024

Don't think so, but a theory - https://github.com/Danielhiversen/pySwitchbot/blob/9a36e4ee5934f0fb3f67ad25e6472b3796d346af/switchbot/devices/blind_tilt.py#L106 is the only reference I see to motionDirection. The only time it's not is on line 84, https://github.com/Danielhiversen/pySwitchbot/blob/9a36e4ee5934f0fb3f67ad25e6472b3796d346af/switchbot/devices/blind_tilt.py#L84 if that if statement triggers, we're accessing a null object.

Same issue might exist for curtains, but wouldn't blow up since we're not dereferencing a null object. I can't see any harm in adding a check for None since very clearly the backing library can return that.

I'll play around with my curtains too later today to see if I can get the scenario to return None.

@dcmeglio
Copy link
Contributor

I haven't been able to reproduce it, but digging through the code pyswitchbot should log Unsuccessful, please try again if my theory is correct

https://github.com/Danielhiversen/pySwitchbot/blob/9a36e4ee5934f0fb3f67ad25e6472b3796d346af/switchbot/devices/device.py#L551C28-L551C58

@c0nt4x do you see that in the logs?

@c0nt4x
Copy link
Author

c0nt4x commented Jan 16, 2024

@dcmeglio Unfortunately, I suffered issues yesterday with my Homeassistant so had to reload a previous backup so am unable to check the logs for when I first saw this issue. I've checked the logs for today and cannot see Unsuccessful, please try again

@glbailey
Copy link

Exactly same error log happening here as OP. Same Home Assistant OS setup but on 2024.1.2 (Same error has been around at least from 2023.10.1 or before)

@dcmeglio
Copy link
Contributor

@glbailey Do you see the log entry I asked about? Unsuccessful, please try again ?

@glbailey
Copy link

No sign at all of "Unsuccessful, please try again" in any of the logs, only the error message the OP showed.
I might also add that the error seems to only show up after a restart, but the device operates without any issues.

@dcmeglio
Copy link
Contributor

When this happens, what is the current position set to? By any chance is it set to Unknown?

@derekcentrico
Copy link

derekcentrico commented Feb 2, 2024

I've been having this a lot lately. First automation will run and then this error happens and I have to reboot the HA VM to get it to work again. Of note, this just happens randomly during the day (like today at noon) when no automation would run. I do sunrise and sunset routines.

Logger: homeassistant.components.bluetooth.manager
Source: components/bluetooth/manager.py:109
Integration: Bluetooth (documentation, issues)
First occurred: 12:29:15 PM (10 occurrences)
Last logged: 12:32:26 PM

Error in bluetooth callback
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/bluetooth/manager.py", line 109, in _discover_service_info
callback(service_info, BluetoothChange.ADVERTISEMENT)
File "/usr/src/homeassistant/homeassistant/components/switchbot/coordinator.py", line 114, in _async_handle_bluetooth_event
super()._async_handle_bluetooth_event(service_info, change)
File "/usr/src/homeassistant/homeassistant/components/bluetooth/active_update_coordinator.py", line 163, in _async_handle_bluetooth_event
super()._async_handle_bluetooth_event(service_info, change)
File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_coordinator.py", line 89, in _async_handle_bluetooth_event
self.async_update_listeners()
File "/usr/src/homeassistant/homeassistant/components/bluetooth/passive_update_coordinator.py", line 51, in async_update_listeners
update_callback()
File "/usr/src/homeassistant/homeassistant/components/switchbot/cover.py", line 188, in _handle_coordinator_update
self._attr_is_opening = self.parsed_data["motionDirection"]["opening"]
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
KeyError: 'motionDirection'

@derekcentrico
Copy link

Switched to the HA Green yesterday evening for fun. Same random issues. 9pm last night the issue happened on the Green. Last blind adjustment was 635pm. Seems like an issue just idly pinging the devices and then cascading into a problem where BT won't work when an automation calls later down the line.

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@issue-triage-workflows issue-triage-workflows bot closed this as not planned Won't fix, can't repro, duplicate, stale May 13, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jun 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants