core icon indicating copy to clipboard operation
core copied to clipboard

Bluetooth Manager Callback error MotionDirection

Open c0nt4x opened this issue 1 year ago • 7 comments

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

c0nt4x avatar Jan 15 '24 12:01 c0nt4x

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[bot] avatar Jan 15 '24 12:01 home-assistant[bot]

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)

home-assistant[bot] avatar Jan 15 '24 12:01 home-assistant[bot]

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

joostlek avatar Jan 15 '24 12:01 joostlek

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.

dcmeglio avatar Jan 15 '24 14:01 dcmeglio

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?

joostlek avatar Jan 15 '24 14:01 joostlek

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 avatar Jan 15 '24 14:01 dcmeglio

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?

dcmeglio avatar Jan 16 '24 00:01 dcmeglio

@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

c0nt4x avatar Jan 16 '24 16:01 c0nt4x

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)

glbailey avatar Jan 18 '24 17:01 glbailey

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

dcmeglio avatar Jan 19 '24 03:01 dcmeglio

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.

glbailey avatar Jan 19 '24 23:01 glbailey

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

dcmeglio avatar Jan 20 '24 16:01 dcmeglio

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 avatar Feb 02 '24 17:02 derekcentrico

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.

derekcentrico avatar Feb 06 '24 11:02 derekcentrico

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.