home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.8k stars 30.89k forks source link

Xiaomi_miio: Error on device update (Vacuum) #43836

Closed faaafo closed 3 years ago

faaafo commented 3 years ago

The problem

I can’t tell since when I got this error. Updating the raspi host nor hassio(docker) didn’t help.

Environment

Supervisor > Homeassistant Core 0.113.2 
Docker Variant

Problem-relevant configuration.yaml

    vacuum:
      - platform: xiaomi_miio
        host: 192.168.178.21
        token: mytoken

Traceback/Error logs

    Traceback (most recent call last):
      File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 320, in _async_add_entity
        await entity.async_device_update(warning=False)
      File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 465, in async_device_update
        await self.hass.async_add_executor_job(
      File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
        result = self.fn(*self.args, **self.kwargs)
      File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/vacuum.py", line 481, in update
        self._timers = self._vacuum.timer()
      File "/usr/local/lib/python3.8/site-packages/miio/vacuum.py", line 377, in timer
        timezone = self.timezone()
      File "/usr/local/lib/python3.8/site-packages/miio/vacuum.py", line 552, in timezone
        res = self.send("get_timezone")[0]
    TypeError: 'int' object is not subscriptable

Additional information

Running mirobo on the raspi or docker instance works as well:

mirobo --ip 192.168.178.21 --token mytoken

State: Charging
Battery: 100 %
probot-home-assistant[bot] commented 3 years ago

Hey there @rytilahti, @syssi, @starkillerog, mind taking a look at this issue as its been labeled with an integration (xiaomi_miio) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

rytilahti commented 3 years ago

Could you please try mirobo -d timezone? Here's what it's returning to me:


DEBUG:miio.miioprotocol:192.168.xx:54321 >>: {'id': 281, 'method': 'get_timezone', 'params': []}
DEBUG:miio.miioprotocol:192.168.xx:54321 (ts: 1970-01-01 20:32:17, id: 281) << {'result': ['Europe/Berlin'], 'id': 281}
faaafo commented 3 years ago

root@raspberrypi:~# docker exec -it homeassistant bash

bash-5.0# mirobo --ip 192.168.178.21 --token mytoken -d timezone

INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Read stored sequence ids: {'seq': 23, 'manual_seq': 0}
DEBUG:miio.vacuum_cli:Connecting to 192.168.178.21 with token mytoken
DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b''
DEBUG:miio.miioprotocol:Got a response: Container: 
    data = Container: 
        data = b'' (total 0)
        value = b'' (total 0)
        offset1 = 32
        offset2 = 32
        length = 0
    header = Container: 
        data = b'!1\x00 \x00\x00\x00\x00\x03L\x83x\x00\x00\xa7\xd5' (total 16)
        value = Container: 
            length = 32
            unknown = 0
            device_id = b'\x03L\x83x' (total 4)
            ts = 1970-01-01 11:56:05
        offset1 = 0
        offset2 = 16
        length = 16
    checksum = b'\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff' (total 16)
DEBUG:miio.miioprotocol:Discovered 034c8378 with ts: 1970-01-01 11:56:05, token: b'ffffffffffffffffffffffffffffffff'
DEBUG:miio.miioprotocol:192.168.178.21:54321 >>: {'id': 24, 'method': 'get_timezone', 'params': []}
DEBUG:miio.miioprotocol:192.168.178.21:54321 (ts: 1970-01-01 11:56:06, id: 24) << {'result': 0, 'id': 24}
Traceback (most recent call last):
  File "/usr/local/bin/mirobo", line 8, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python3.8/site-packages/miio/click_common.py", line 59, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/decorators.py", line 73, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/miio/vacuum_cli.py", line 537, in timezone
    click.echo("Timezone: %s" % vac.timezone())
  File "/usr/local/lib/python3.8/site-packages/miio/vacuum.py", line 552, in timezone
    res = self.send("get_timezone")[0]
TypeError: 'int' object is not subscriptable
bash-5.0# 
ldobransky commented 3 years ago

same issue on my side

XRedShark commented 3 years ago

My Xiaomi Vacuum Mop v2 is "unavailable"

ShifuEst commented 3 years ago

I have same problem. My Xiaomi Vacuum Mop v2 is "unavailable" https://imgur.com/EvKVkJB

gerben-van-eck commented 3 years ago

Same issue.

On first attempt, I got Error: Unable to discover the device 192.168.178.235

After that, I pinged that IP, it only responded after a few seconds.

On my second attempt, I got the same log as faaafo.

rytilahti commented 3 years ago

@faaafo for the timezone problem, please create an upstream issue at https://github.com/rytilahti/python-miio/ . For some reason the device is not reporting the timezone information correctly, which is required for the timer functionality.

However, the missing timer information should not cause a verbose exception since #41330 (merged already in October) so you should simply try to update to a newer homeassistant version to see if it fixes it, with the caveat of not having timer information available for homeassistant.

ShifuEst commented 3 years ago

I Have :)

Version 2021.1.0b1
Installation Type Home Assistant OS
Development false
Supervisor true
Docker true
Virtual Environment false
Python Version 3.8.6
Operating System Family Linux
Operating System Version 5.4.79-v7l
CPU Architecture armv7l
Timezone Europe/Tallinn
Host Operating System Home Assistant OS 5.10
Update Channel beta
Supervisor Version 2020.12.7
Docker Version 19.03.13
Disk Total 13.9 GB
Disk Used 4.8 GB
Healthy true
Supported true
Board rpi4
Supervisor API ok
Version API ok
Installed Add-ons Samba share (9.3.0), OpenZWave (0.7.1), Mosquitto broker (5.1), File editor (5.2.0), Terminal & SSH (8.10.0), Traccar (0.9.2), MariaDB (2.2.1)
faaafo commented 3 years ago

@rytilahti Thank you for chiming in.

Updated the underlying host and homeassistant (2020.12.1) as well. Alas to no avail.

Will gladly follow your suggestion, open an issue on python-miio and keep you/this issue posted

rytilahti commented 3 years ago

@faaafo thanks for chiming in back, too! Okay, that's a bit odd. Does the stacktrace in the logs still look similar, i.e., crashing inside timezone request handling?

ShifuEst commented 3 years ago

i use - platform: miio2 and it's work but / - platform: xiaomi_miio it's not work.

error miio2 but it's work

Got exception while fetching the state: Unable to discover the device 192.168.2.129 12:18:01 AM – miio2 (WARNING) - message first occurred at January 3, 2021, 10:04:28 PM and shows up 56 times Update of vacuum.robottolmuimeja is taking over 10 seconds 12:18:01 AM – helpers/entity.py (WARNING) - message first occurred at January 3, 2021, 10:05:39 PM and shows up 29 times Choked at offset 12 while unpacking b"@.UO\x0f\x18\x19+\x11X(?\x0fF\x16\x0b#hV#\x1a[0\x19\x00\x13\x0fV%hNe!$40<N[M&\x03\r6I#Am\x0c\x17\x10&rA?rTNHy6\x17^W;\x13\x07wabD\x07fQ=/u~\x1c\x01\x15-'\x08nfzB4C<jZ\x1aA\x15-r\xad" January 3, 2021, 11:31:45 PM – /usr/local/lib/python3.8/site-packages/zeroconf/init.py (WARNING) DeviceException during setup of xiaomi gateway with host 192.168.2.129 January 3, 2021, 10:05:28 PM – Xiaomi Miio (ERROR) Waiting on integrations to complete setup: upnp, xiaomi_miio January 3, 2021, 10:05:05 PM – bootstrap.py (WARNING) Error while setting up samsungtv platform for media_player January 3, 2021, 10:05:02 PM – Media player (ERROR) You are using a custom integration for miio2 which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant. January 3, 2021, 10:04:58 PM – loader.py (WARNING) - message first occurred at January 3, 2021, 10:03:10 PM and shows up 2 times

ShifuEst commented 3 years ago

miio2 it work pic

https://ibb.co/Gx6vRNL

faaafo commented 3 years ago

Current log

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 359, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 466, in async_device_update
    await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/vacuum.py", line 495, in update
    self._timers = self._vacuum.timer()
  File "/usr/local/lib/python3.8/site-packages/miio/vacuum.py", line 398, in timer
    timezone = pytz.timezone(self.timezone())
  File "/usr/local/lib/python3.8/site-packages/miio/vacuum.py", line 576, in timezone
    res = self.send("get_timezone")[0]
TypeError: 'int' object is not subscriptable
faaafo commented 3 years ago

@ShifuEst What is miio2?

rytilahti commented 3 years ago

@faaafo ah, indeed, the PR I linked fixes only the cases where a DeviceException is raised (so this typeerror won't be caught).

miio2 is a custom fork of the integration for some non-rockrobo (viomi) devices. Issues with that should be reported to its developer and not in this repository.

ShifuEst commented 3 years ago

https://github.com/nqkdev/home-assistant-vacuum-styj02ym

this is miio2 and it's work

ShifuEst commented 3 years ago

if I use vacuum:

ShifuEst commented 3 years ago

Update of vacuum.robottolmuimeja is taking over 10 seconds 1:25:57 AM – helpers/entity.py (WARNING) - message first occurred at 1:23:57 AM and shows up 3 times Got error when receiving: timed out 1:25:27 AM – /usr/local/lib/python3.8/site-packages/miio/miioprotocol.py (ERROR) - message first occurred at 1:22:46 AM and shows up 7 times Updating xiaomi_miio vacuum took longer than the scheduled update interval 0:00:20 1:25:27 AM – Vacuum (WARNING) - message first occurred at 1:24:07 AM and shows up 4 times Setup of vacuum platform xiaomi_miio is taking over 10 seconds. 1:22:56 AM – Vacuum (WARNING) DeviceException during setup of xiaomi gateway with host 192.168.2.129 1:22:46 AM – Xiaomi Miio (ERROR)

ShifuEst commented 3 years ago

if I use miio2 then is ok :)

ShifuEst commented 3 years ago
#                                                  #
####################################################  

vacuum:

ShifuEst commented 3 years ago

look miio2 platform work. :)

https://ibb.co/DMHDNZH

ShifuEst commented 3 years ago

Moi. Puhun myös vähän suomea :)

vukisz commented 3 years ago

Same error for the no roborock S7:

Logger: homeassistant.components.vacuum
Source: components/xiaomi_miio/vacuum.py:499
Integration: Vacuum (documentation, issues)
First occurred: 11:54:56 AM (1 occurrences)
Last logged: 11:54:56 AM

xiaomi_miio: Error on device update!
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 360, in _async_add_entity
    await entity.async_device_update(warning=False)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 465, in async_device_update
    await task
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/vacuum.py", line 499, in update
    self.last_clean = self._device.last_clean_details()
  File "/usr/local/lib/python3.8/site-packages/miio/vacuum.py", line 352, in last_clean_details
    if not history.ids:
  File "/usr/local/lib/python3.8/site-packages/miio/vacuumcontainers.py", line 219, in ids
    return list(self.data[3])
KeyError: 3
rytilahti commented 3 years ago

@vukisz that looks like a completely different problem (protocol incompatibility) than the ones mentioned earlier.

Could you please activate debug logger for miio and observe the responses from the device (get_clean_summary and get_clean_record are relevant method calls), and create a new issue at https://github.com/rytilahti/python-miio/ ?

@ShifuEst moi moi :-)

rytilahti commented 3 years ago

The timezone issue should have been fixed for a long time ago already (0.5.5, https://github.com/rytilahti/python-miio/pull/949), and a fix to the s7 issue got fixed in 0.5.6 which is used by 2021.5.1, so I'm closing this now.