SecKatie / wyzeapy

35 stars 26 forks source link

List Index out of Range #71

Open malammar opened 1 year ago

malammar commented 1 year ago

I have a couple of Wyze Lock Bolts and they seem to be causing an out of range error in this integration:

home-assistant  | 2023-08-04 13:48:31.221 ERROR (MainThread) [homeassistant.components.lock] wyzeapi: Error on device update!
home-assistant  | Traceback (most recent call last):
home-assistant  |   File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 570, in _async_add_entity
home-assistant  |     await entity.async_device_update(warning=False)
home-assistant  |   File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 940, in async_device_update
home-assistant  |     await self.async_update()
home-assistant  |   File "/config/custom_components/wyzeapi/token_manager.py", line 45, in inner_function
home-assistant  |     await func(*args, **kwargs)
home-assistant  |   File "/config/custom_components/wyzeapi/lock.py", line 149, in async_update
home-assistant  |     lock = await self._lock_service.update(self._lock)
home-assistant  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/lock_service.py", line 18, in update
home-assistant  |     device_info = await self._get_lock_info(lock)
home-assistant  |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
home-assistant  |   File "/usr/local/lib/python3.11/site-packages/wyzeapy/services/base_service.py", line 499, in _get_lock_info
home-assistant  |     device_uuid = device.mac.split(".")[2]
home-assistant  |                   ~~~~~~~~~~~~~~~~~~~~~^^^
home-assistant  | IndexError: list index out of range

I don't really need those locks supported but this is impacting updates to my other Wyze devices.

SecKatie commented 1 year ago

Looks like they changed how the device address is configured... Is it possible to find what the actual value is so we can parse it correctly?

@malammar can you add a debug log statement to wyzeapy/services/base_service.py and share the line in the log?

malammar commented 1 year ago

I have an old debug log from lock_service.py which might have what you're looking for:

[
  {
    "available": false,
    "raw_dict": {
      "mac": "YD_BT1.39aa4f3a9267557ddee4043da924c704",
      "first_activation_ts": 1654131355000,
      "first_binding_ts": 1654131355000,
      "enr": "",
      "nickname": "Front Door",
      "timezone_name": "America/Los_Angeles",
      "product_model": "YD_BT1",
      "product_model_logo_url": "",
      "product_type": "Lock",
      "hardware_ver": "0.0.0.0",
      "firmware_ver": "1.0.0",
      "user_role": 1,
      "binding_user_nickname": "REDACTED",
      "conn_state": 1,
      "conn_state_ts": 0,
      "push_switch": 1,
      "device_params": {},
      "is_in_auto": 0,
      "event_master_switch": 1,
      "parent_device_mac": "",
      "parent_device_enr": "",
      "binding_ts": 1654131355000,
      "timezone_gmt_offset": -7.0
    }
  }
]
JoeSchubert commented 10 months ago

@SecKatie

Looking at the output malamar posted there, I feel like they used to have "something.somethingelse.uuid" and they removed one of the somethings.

however, I'm not sure if some versions of the lock still have 3 fields? So maybe it's just worth changing device_uuid = device.mac.split(".")[2] to device_uuid = device.mac.split(".")[-1]

Those changes will need to be here: https://github.com/SecKatie/wyzeapy/blob/bb5323b3a394118bfd7e5fafeb9253984e987617/src/wyzeapy/services/base_service.py#L480 and here: https://github.com/SecKatie/wyzeapy/blob/bb5323b3a394118bfd7e5fafeb9253984e987617/src/wyzeapy/services/base_service.py#L499

I think it was always the last segment of the mac when split by .'s