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
74.13k stars 31.12k forks source link

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

Closed Kirbo closed 5 months ago

Kirbo commented 1 year ago

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

home-assistant[bot] commented 1 year ago

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)

Kirbo commented 1 year ago

Issue is still present

chriswood1001 commented 1 year ago

Issue is still present in Home Assistant 2023.11.1

Kirbo commented 1 year ago

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

serlinGi commented 1 year ago

same issue, HA 2023.11.2

zollek commented 1 year ago

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

rytilahti commented 1 year ago

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).

zollek commented 9 months ago

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.

quenthal commented 9 months ago

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)

rytilahti commented 8 months ago

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.

issue-triage-workflows[bot] commented 5 months ago

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.