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

Switchbot Lock IndexError #89061

Closed
wdenton2 opened this issue Mar 2, 2023 · 61 comments · Fixed by #90146
Closed

Switchbot Lock IndexError #89061

wdenton2 opened this issue Mar 2, 2023 · 61 comments · Fixed by #90146

Comments

@wdenton2
Copy link

wdenton2 commented Mar 2, 2023

The problem

After upgrading to home assistant 2023.3 the the Switchbot lock works after restart, but after some time will generate an error of "IndexError: bytearray index out of range". This lock is connected via an esp32 running the ESPhome Home assistant bluetooth proxy.

What version of Home Assistant Core has the issue?

2023.3

What was the last working version of Home Assistant Core?

2023.2

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Switchbot

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.components.websocket_api.http.connection
Source: components/switchbot/lock.py:54 
Integration: Home Assistant WebSocket API (documentation, issues) 
First occurred: 2:41:26 PM (5 occurrences) 
Last logged: 2:43:03 PM

[140336955975392] bytearray index out of range
[140336996131280] bytearray index out of range
[140336906908960] bytearray index out of range
[140337048416464] bytearray index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 198, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 726, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 106, in _async_unlock
    await entity.async_unlock(**remove_entity_service_fields(service_call))
  File "/usr/src/homeassistant/homeassistant/components/switchbot/lock.py", line 54, in async_unlock
    self._last_run_success = await self._device.unlock()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 168, in unlock
    return await self._lock_unlock(
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 196, in _lock_unlock
    self._update_parsed_data(self._parse_basic_data(basic_data))
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 175, in _parse_basic_data
    "battery": basic_data[1],
IndexError: bytearray index out of range

Additional information

No response

@home-assistant
Copy link

home-assistant bot commented Mar 2, 2023

Hey there @bdraco, @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.

(message by CodeOwnersMention)


switchbot documentation
switchbot source
(message by IssueLinks)

@KitHubek
Copy link

KitHubek commented Mar 2, 2023

the same here

#89066

@wdenton2
Copy link
Author

wdenton2 commented Mar 2, 2023

Quick update, the lock may also become unavailable after giving the IndexError. It has to be deleted and re-added to show up again. Not sure whether this is an issue with the bluetooth proxy or the integration. Sometimes the lock can be re-added after a restart, others the bluetooth proxy needs to be restarted.

@KitHubek
Copy link

KitHubek commented Mar 2, 2023

yes, but restarting every x time lock or integration or esp isnt good idea

@PeterJacobsenDenmark
Copy link

I am experiencing the same issue.

@KitHubek
Copy link

KitHubek commented Mar 3, 2023

back to the February release solve problem, so this is for sure march release problem
Someone checked newest release 2023.3.1 ? Problem solved after .1 update?

@alsFC
Copy link

alsFC commented Mar 3, 2023

Facing the same error also in .1 update.

@jpconfessor
Copy link

Same problem here... it seems to be linked to python 3.11 update (just a BIG guess here)
I will have to downgrade. Hopefully this gets fixed soon!

@yourjelly
Copy link

yourjelly commented Mar 6, 2023

Same problem here on 2023.3.1, reverting to 2023.3.0 seems to resolve it for the time being

@federicotravaini
Copy link

Same problem here after 2023.2

Reloading the integration fixes the issue but then it keep happening again and again

image

@JamieSBenson
Copy link

Same here-- unable to restore functionality even with a backup at this point in time.

@bdraco
Copy link
Member

bdraco commented Mar 6, 2023

I don't have the issue but I'm running firmware 6.2 on the lock

@federicotravaini
Copy link

I don't have the issue but I'm running firmware 6.2 on the lock

I am on V6.5 and get the error every couple of hours

@bdraco bdraco changed the title Switchbot Lock IndexError Switchbot Lock IndexError with firmware v6.5 Mar 6, 2023
@devilization
Copy link

devilization commented Mar 7, 2023

I don't have the issue but I'm running firmware 6.2 on the lock

I'm having the same issues even though i was running firmware v6.2

firmware

ha-ver

My log as below:

Logger: homeassistant.components.websocket_api.http.connection
Source: components/switchbot/lock.py:49
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 2:07:34 PM (1 occurrences)
Last logged: 2:07:34 PM

[139671504912688] bytearray index out of range
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 198, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1808, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1845, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 686, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 961, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 726, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/lock/__init__.py", line 96, in _async_lock
    await entity.async_lock(**remove_entity_service_fields(service_call))
  File "/usr/src/homeassistant/homeassistant/components/switchbot/lock.py", line 49, in async_lock
    self._last_run_success = await self._device.lock()
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 162, in lock
    return await self._lock_unlock(
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 196, in _lock_unlock
    self._update_parsed_data(self._parse_basic_data(basic_data))
  File "/usr/local/lib/python3.10/site-packages/switchbot/devices/lock.py", line 175, in _parse_basic_data
    "battery": basic_data[1],
IndexError: bytearray index out of range

@bdraco bdraco changed the title Switchbot Lock IndexError with firmware v6.5 Switchbot Lock IndexError Mar 7, 2023
@christi-g
Copy link

Same problem after upgrade to 2023.3

@jpconfessor
Copy link

Can someone check if this was fixed in 2023.3.2?

@JamieSBenson
Copy link

JamieSBenson commented Mar 8, 2023

Can someone check if this was fixed in 2023.3.2?

Appears to be working as expected for me now! Though I've had sporadic function lately. Will edit this reply if I find it is not working again later.

**EDIT: Yeah, still broken. **

@wdenton2
Copy link
Author

wdenton2 commented Mar 8, 2023

Still broken for me in 2023.3.2. Same as before. Will respond normally for a bit until it give the same IndexError.

Edit: It appears the state changes when manually unlocking/locking and the door state changes as well now. Door state did not previously work for me. However I cannot send a lock/unlock command. Same error.

@tiger52524949
Copy link

I can confirm that 2023.3.2 did not fix the problem.

@reniewk
Copy link

reniewk commented Mar 9, 2023

The problem indeed persists in 2023.3.2.

@wardwolfram
Copy link

I have the same issue here...

image

@beele
Copy link
Contributor

beele commented Mar 10, 2023

Experiencing the same issue.

@KiraPC
Copy link

KiraPC commented Mar 12, 2023

Same issue for me!

@goaliedude3919
Copy link

I am experiencing the same issue as well on 2023.3.3

Home Assistant 2023.3.3
Supervisor 2023.03.1
Operating System 9.5
Frontend 20230309.0 - latest

I reverted back to 2023.2.5 and it works again.

@KitHubek
Copy link

i too.
2 weeks gone and critical upgrade no exsist.
I think abut change lock and all switchbot devices to another brand

@danir-de
Copy link

I think abut change lock and all switchbot devices to another brand

This has nothing to do with the Switchbot Locks themselves.
The error comes from Home Assistant 2023.03.

Either Roll-Back to an earlier backup (prior 2023.03) or wait for a fix.

@walk0080
Copy link

great idea! but my lock doesn't show as 'unavailable' when I get this error. Still shows online like its working

That is when I use the button that reloads the integration, but you can also create a button that first reload the automation, and then open/close the switchbot, so it should be working all the time

In my case, the SwitchBot Lock also does not show “unavailable” in HA just prior to failing - the lock appears working normal, showing battery level, etc. And the SwitchBot Integration appears OK as well. Recyling the Integration immediately causes the lock to run I on again.

Appreciate the automations posted here. This should help for now until a fix is available in the future. :-)

@oneseventhree
Copy link

is this fixed in newest version HA 2023.3.4 ?

nope - reloading the integration is the bypass for now

@captshadab
Copy link

Problem solved for me in latest core update

@KiraPC
Copy link

KiraPC commented Mar 17, 2023

Problem solved for me in latest core update

Strange, it is not mentioned in the changelog.

@captshadab
Copy link

Problem solved for me in latest core update

Update: it's still intermittent however works better than previous time. Still the error message exists. Tested after 12 hours of inactivity and it worked couple of time. After that after an hour it did not and after few mins it did. So it's weird

@wardwolfram
Copy link

Works better for me as well. But will crash ever so often. Then must reload the service.

@herveaurel
Copy link

Same here. HA 2023.3.3.

@KitHubek
Copy link

@Danielhiversen
@bdraco

is some progress with this issue? 3 weeks gone...

@federicotravaini
Copy link

Yeah an update about a work in progress would be much appreciated. Right know the lock is 99% of the time unreliable.

@bdraco
Copy link
Member

bdraco commented Mar 21, 2023

I don't think anyone is working on this. Someone who can replicate the issue will need to fix it. I can review a fix when someone comes up with one but that's the extent to which I can help here.

@federicotravaini
Copy link

@KiraPC any chance you can look into this issue?

@KiraPC
Copy link

KiraPC commented Mar 21, 2023

Hi @federicotravaini I was looking to the diff from the old February release and the first of march but I didn't see any changes on Switchbot files. I think it is an issue on the new python version.

In this weekend if I have time I'll try to take some debugs for investigate.

Btw, does someone has it installed not as container but with python? In case, with python 10 it has the same error?

Edit: I read better the log, it is python10, but the error coming from the switchbot lib, not from hass

Edit 2: the only changes from 2022.2.5 is the update of the PySwitchbot lib from 0.36.4 to 0.37.3 so I think this issue is opened to the wrong repository.

Tomorrow I'll open it to the correct one if no other do it before me (if you'll do, please tag me)

@bdraco
Copy link
Member

bdraco commented Mar 23, 2023

Should be fixed in 2023.3.6 thanks to the person who didn't wanted to be named that mailed me a lock that had the issue.

@yourjelly
Copy link

yourjelly commented Mar 23, 2023 via email

@brintal
Copy link

brintal commented Mar 26, 2023

I do not think this is fixed. I upgraded to 2023.3.6 because I was experiencing the same symptoms as described above.
After upgrading the symptoms actually seem more severe. The Lock becomes completely unavailable and just reloading the switchbot integration is not enough anymore. HA can't find the Lock anymore.
To fix it, I have to restart the Bluetooth proxy and then the switchbot integration.

@KitHubek
Copy link

Yes @brintal i have the same problem when upgrading to 2023.3.6
Fixed is downgrade to max 2023.2.5 or as You wrote - relolad integration

#90265 (comment)

@walk0080
Copy link

So far appears to be fixed for my lock and HA setup using 2023.3.6.

@bdraco
Copy link
Member

bdraco commented Mar 26, 2023

I do not think this is fixed. I upgraded to 2023.3.6 because I was experiencing the same symptoms as described above.

After upgrading the symptoms actually seem more severe. The Lock becomes completely unavailable and just reloading the switchbot integration is not enough anymore. HA can't find the Lock anymore.

To fix it, I have to restart the Bluetooth proxy and then the switchbot integration.

Unless you have the exact same error as the op in the log, please open a new issue as you have a different problem.

Please include full debug logs in the new issue

@rVlad93
Copy link

rVlad93 commented Apr 8, 2023

Updated yesterday to 2023.4 and the lock is back and working as before.

@github-actions github-actions bot locked and limited conversation to collaborators May 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.