core icon indicating copy to clipboard operation
core copied to clipboard

Xiaomi Miio - Unexpected error fetching <device> data: byte indices must be integers or slices, not str

Open Kirbo opened this issue 1 year ago • 8 comments

The problem

Logger: homeassistant.components.xiaomi_miio
Source: components/xiaomi_miio/__init__.py:175
Integration: Xiaomi Miio (documentation, issues)
First occurred: June 30, 2023 at 09:09:19 (3 occurrences)
Last logged: 08:45:09

Unexpected error fetching Ilmankostutin data: byte indices must be integers or slices, not str
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 283, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 242, in _async_update_data
    return await self.update_method()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/__init__.py", line 180, in update
    return await _async_fetch_data()
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/xiaomi_miio/__init__.py", line 175, in _async_fetch_data
    state = await hass.async_add_executor_job(device.status)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/click_common.py", line 184, in _wrap
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/integrations/humidifier/zhimi/airhumidifier.py", line 302, in status
    values = self.get_properties(properties, max_properties=_props_per_request)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/device.py", line 240, in get_properties
    values.extend(self.send(property_getter, _props[:max_properties]))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/device.py", line 107, in send
    return self._protocol.send(
           ^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/miio/miioprotocol.py", line 202, in send
    self.__id = payload["id"]
                ~~~~~~~^^^^^^
TypeError: byte indices must be integers or slices, not str

What version of Home Assistant Core has the issue?

core-2023.6.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Xiaomi Miio

Link to integration documentation on our website

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

Diagnostics information

home-assistant_xiaomi_miio_2023-07-01T13-24-24.362Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

Kirbo avatar Jul 01 '23 13:07 Kirbo

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

Code owner commands

Code owners of xiaomi_miio 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 xiaomi_miio Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


xiaomi_miio documentation xiaomi_miio source (message by IssueLinks)

home-assistant[bot] avatar Jul 01 '23 13:07 home-assistant[bot]

Issue is still present

Kirbo avatar Aug 16 '23 14:08 Kirbo

Issue is still present in Home Assistant 2023.11.1

  • zhimi.airpurifier.mb3, and
  • zhimi.airpurifier.mb4

chriswood1001 avatar Nov 07 '23 00:11 chriswood1001

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

https://github.com/home-assistant/core/issues/95669#issuecomment-1615909218

Kirbo avatar Nov 07 '23 09:11 Kirbo

same issue, HA 2023.11.2

serlinGi avatar Nov 16 '23 20:11 serlinGi

Same issue here for zhimi.humidifier.cb1. This error is a cause of device disconnect.

zollek avatar Nov 21 '23 22:11 zollek

So, this happens when the device responses with something that is not a json object. It would be very helpful if you could try to access the device using miiocli -dd airhumidifier --ip <ip> --token <token> status (note two ds) to trigger https://github.com/rytilahti/python-miio/blob/9b17d906d3829dd861d4cb73982dad7d9a5a8e95/miio/miioprotocol.py#L197 find out what is going on.

You can locate the token either by using miiocli cloud command or extracting it from the config entry file (~/.homeassistant/.storage/core.config_entries).

rytilahti avatar Nov 21 '23 23:11 rytilahti

Hi, I was finally able to set up python environment and could run miiocli: zhimi.humidifier.cb1 status.txt

If there's anything more needed just lep me know.

zollek avatar Feb 07 '24 20:02 zollek

are more logs needed? i've two smarti humidifiers that are "suffering" from this same issue.

(These seem to happen (only) twice a day, so naturally not with every status update or something like that)

quenthal avatar Feb 21 '24 06:02 quenthal

No need for more logs, if this is not something that is happening for every update. I created an upstream issue to track this https://github.com/rytilahti/python-miio/issues/1913, but in the meanwhile, maybe we could catch that typeerror and just log it instead of erroring out?

This wouldn't fix the real issue (most likely some fw issue), but it could make it less annoying when the device is just marked as unavailable instead of throwing an exception.

rytilahti avatar Mar 15 '24 23:03 rytilahti

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.