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

Bug(AC): AC设备No Query Protocol循环导致High CPU #421

Closed
justmagic7211 opened this issue Dec 22, 2024 · 25 comments · Fixed by midea-lan/midea-local#346
Closed

Bug(AC): AC设备No Query Protocol循环导致High CPU #421

justmagic7211 opened this issue Dec 22, 2024 · 25 comments · Fixed by midea-lan/midea-local#346
Labels
bug Something isn't working
Milestone

Comments

@justmagic7211
Copy link

HA版本

2024.12.5

集成版本

0.6.5

之前可正常使用的集成版本

v0.6.5

设备类型及型号

Air Conditioner 22396409 (44204)

使用的App

美的美居

问题/Bug详细描述

中央空调,未进行任何操作,多次出现HASS cpu占用过高,
image
当我尝试禁用实体后,cpu占用下降,查看日志发现,进入循环
2024-12-22 20:58:58.377 WARNING (MainThread) [homeassistant.util.loop] Detected blocking call to open with args ('/config/.storage/midea_ac_lan/210006726902963.json',) inside the event loop by custom integration 'midea_ac_lan' at custom_components/midea_ac_lan/config_flow.py, line 156: return load_json(f.name, default={}) (offender: /usr/src/homeassistant/homeassistant/util/json.py, line 72: with open(filename, mode="rb") as fdesc:), please create a bug report at https://github.com/wuwentao/midea_ac_lan/issues
midea_lan.log

The logs

  1. 必须先开启Debug Log(参考首页README说明)
  2. 执行产生错误的操作(请务必在问题详细描述中说明)
  3. 将完整的Debug log文件以附件上传。
  4. 请勿直接粘贴log中的部分内容!以附件上传。
  5. 请勿直接粘贴log中的部分内容!以附件上传。
  6. 请勿直接粘贴log中的部分内容!以附件上传。
    ...
@justmagic7211 justmagic7211 added the bug Something isn't working label Dec 22, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Title: Read the json file and enter the loop

@wuwentao
Copy link
Owner

@justmagic7211 这个是HAOS 的warning message,不会影响任何东西,仅仅是需要随后替换为async模式的异步IO而已。

请明确你使用的HAOS版本,HA core版本,我之前也遇到一个老版本的HA Core自身有问题,会有high cpu问题,但是升级最新版HA core,恢复正常。
目前尚未发现其他人有报告类似问题,而且这一块代码最近几个月均未修改,正常来说,不会有问题。
所以建议直接升级你的HA core到最新版确认问题原因,HAOS版本不重要,主要是core

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@justmagic7211 This is a warning message of HAOS. It will not affect anything. It just needs to be replaced with asynchronous IO in async mode later.

Please be clear about the HAOS version and HA core version you are using. I also encountered an old version of HA Core that had problems with itself and high cpu problems. However, after upgrading to the latest version of HA core, it returned to normal.
No one else has reported similar problems so far, and this piece of code has not been modified in recent months. Normally, there will be no problems.
Therefore, it is recommended to directly upgrade your HA core to the latest version to confirm the cause of the problem. The HAOS version is not important, mainly the core

@justmagic7211
Copy link
Author

justmagic7211 commented Dec 25, 2024

我已经升级到最新的haos,版本号2024.12.5,只要我尝试启用上述的实体后,cpu占用就会上升,同时日志无限重复
image

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I have upgraded to the latest haos, version number 2014.12.5. As soon as I try to enable the above entities, the cpu usage will increase and the log will repeat indefinitely.

@wuwentao
Copy link
Owner

@justmagic7211 先不说cpu上升的问题,最后的日志无限重复是什么意思?
是这一段打印无限循环? 这个原则上是不可能,也不正常的,除非您进入了或者导致某个东西改出问题了,或者手工修改过源码或者啥配置之类的。

因为这段json文件的读或写,只会是启动discover向导,发现设备,添加新设备,才会执行。

如果HA 正常启动,加载midea_ac_lan,原则上也是不会进入这个读取json的流程,也不会触发这个warning message,所以您到底是什么问题呢?
而且一直仅仅是文字描述,debug log并未提供,尤其是从启动开始的log,将debug配置添加进configuration.yaml中,重启HA,看看输出什么内容无限循环。
如果是连接设备失败的,那是正常输出,如果是其他错误输出,请给出完整的debug log file。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@justmagic7211 Let’s not talk about the problem of CPU increase. What does the last log repeating infinitely mean?
Is this section printing an infinite loop? In principle, this is impossible and abnormal, unless you enter or cause something to change, or manually modify the source code or configuration.

Because the reading or writing of this **json file will only be executed when the discover wizard is started, the device is discovered, and the new device is added. **

If HA starts normally and loads midea_ac_lan, in principle it will not enter the process of reading json, nor will this warning message be triggered, so what is your problem?
And it has always been just a text description, and the debug log is not provided, especially the log from startup. Add the debug configuration to configuration.yaml, restart HA, and see what is output in an infinite loop.
If it fails to connect to the device, it is normal output. If it is other error output, please provide a complete debug log file.

@justmagic7211
Copy link
Author

home-assistant.log
是这个日志吗

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


home-assistant.log
Is it this log?

@wuwentao
Copy link
Owner

@justmagic7211 你就传了1秒钟的log,后面的都没了。
从这个log里,也是不可能有这个json错误的。
但是你的一台空调,是有连接错误的:

2024-12-26 20:56:12.110 DEBUG (MainThread) [midealocal.device] [210006726902963] Socket closed
2024-12-26 20:56:12.111 DEBUG (后卧空调) [midealocal.device] [210006726902963] Connection error
2024-12-26 20:56:12.111 DEBUG (后卧空调) [midealocal.device] [210006726902963] Disabling device
2024-12-26 20:56:12.111 DEBUG (后卧空调) [midealocal.device] [210006726902963] Status update: {'available': False}
2024-12-26 20:56:12.112 WARNING (后卧空调) [midealocal.device] [210006726902963] Unable to connect, sleep 5 seconds and retry

具体问题看不出来,log只有1秒钟的数据,没法确认。这个设备要么是不支持,要么是有其它问题,可能需要更多log,以及设备SN等信息进一步确认。

如果重启空调,重启HA,仍然还是midea_ac_lan导致cpu利用率高,并且禁用midea_ac_lan可以解决问题,那么可以尝试擅长这台设备,看看是否是这台设备的问题(原则上也是不应该的)。而且目前也没有遇到任何人反馈有cpu高的情况。
但是至少可以明确的说,100%不是读取json文件的问题。

@justmagic7211
Copy link
Author

后面基本都是循环的日志,然后也就很奇怪,只需要禁用掉这个设备,另两个是没问题的,也尝试过删除设备,甚至重装插件也还是这样
home-assistant-.log

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The following are basically circular logs, and then it is very strange. I only need to disable this device, and the other two are no problem. I have also tried deleting the device, and even reinstalling the plug-in still has the same problem.
home-assistant-.log

@wuwentao wuwentao changed the title 读取json文件进入循环 Bug(AC): AC设备No Query Protocol循环导致High CPU Dec 27, 2024
@wuwentao
Copy link
Owner

ok, 确认禁用这个设备以后没有high cpu的问题就好办了,我随后改一些地方,你如果可以修改pip库的源,可以自行测试是否解决问题。
如果不会测试,等下次release再尝试吧。
彻底解决的话,仍然需要根据你这台设备的SN信息,匹配对应的协议,根源还是这台设备无法支持,和其他AC空调设备大概率是不一样的。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Ok, it will be easier to solve after confirming that after disabling this device, there will be no high CPU problem. I will change some places later. If you can modify the source of the pip library, you can test whether the problem is solved by yourself.
If you don’t know how to test, wait until the next release and try again.
If it is completely solved, you still need to match the corresponding protocol based on the SN information of your device. The root cause is that this device cannot support it, and it is most likely different from other AC air conditioning devices.

@wuwentao
Copy link
Owner

@justmagic7211

临时加了一个修复,解决这种有异常的设备导致的high cpu问题,可以直接修改pip库的源码,自行测试是否解决,理论上应该问题不大。
只需要新增一行 sleep 1秒即可,3-5秒也行吧,但是1秒应该是足够解决high cpu问题。
具体修改见这里:
midea-lan/midea-local#346

具体修改源码的steps如下,之前发的英文格式的,你参考一下:

brief step:

  1. login to HAOS
  2. start homeassitant docker
  3. replace file for midealocal python pip package in homeassitant core(use wget to download github PR raw file and replace it)
  4. enable debug log for both midea_ac_lan and midealocal in configuration.yaml
  5. reboot HA.

below is the detail steps:

  1. if you are using HAOS, you should install Add-on [Advanced SSH & Web Terminal] and disable [Protected Mode], once it done, you can ssh to your HAOS, and enter docker in HAOS docker exec -it homeassistant /bin/bash, contiune the step to check midea-local install path
  2. if you not using HAOS, just check midea-local install path as the next step
    3.get midea-local install path with command pip show midea-local, it will show info for you, for example, my location is Location: /usr/local/lib/python3.13/site-packages
  3. then we can replace the file under /usr/local/lib/python3.13/site-packages/midealocal/devices/cd/ with the code changes, using vi command line tool or wget to download github raw file.
  4. make sure you have enabled debug log in configuration.yaml
  5. reboot HA and test with it, confirm with the result or debug log.

@justmagic7211
Copy link
Author

配对应的协议,根源还是这台设备无法支持,和其他AC空调设

很奇怪,按道理来讲另两台设备是一样的,有可能是由于网络信号不好?另两台的设备连接wifi的标准是wifi4,但是这台是wifi1。设备SN是0000005112239640934260310749Q2P7,然后我看到你修改的不是midealocal/devices/cd/ 内的文件,我修改的是 midealocal/device.py在未支持的那行加上了sleep(1),目前没有10分钟没有再发现cpu占用的上升

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


The reason for pairing the corresponding protocol is that this device cannot support it and other AC air-conditioning devices

It's strange. Logically speaking, the other two devices are the same. Maybe it's because the network signal is not good? The standard for connecting the other two devices to wifi is wifi4, but this one is wifi1. The device SN is 0000005112239640934260310749Q2P7. Then I saw that what you modified was not the file in midealocal/devices/cd/. What I modified was midealocal/device.py and added sleep(1) to the unsupported line. There has been no increase in CPU usage for 10 minutes.

@wuwentao
Copy link
Owner

wuwentao commented Jan 2, 2025

@justmagic7211 多谢确认,

  1. sleep 1秒应该是可以解决cpu占用的问题。
  2. 那个修改的文件夹我应该是复制粘贴,忘了改了而已。
  3. 这台设备控制模块和另外2台设备的控制模块是不一样的,和你连接的wifi标准没关系,wifi只是联网和通讯,不涉及设备控制。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@justmagic7211 Thanks for confirming,

  1. Sleeping for 1 second should solve the CPU usage problem.
  2. I should have copied and pasted the modified folder and forgot to change it.
  3. The control module of this device is different from the control modules of the other two devices. It has nothing to do with the WiFi standard you are connected to. WiFi is only for networking and communication, and does not involve device control.

@wuwentao
Copy link
Owner

wuwentao commented Jan 2, 2025

@justmagic7211 修复cpu利用率以后,这台设备应该是没有任何支持的数据或功能可用。
如果需要支持这台设备,用不同的github issue跟踪吧,把SN信息,产品详情都描述清楚吧,当前issue单独解决high cpu的问题吧,避免各种不同的问题混淆在一起解决。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@justmagic7211 After fixing the CPU utilization, there should be no supported data or functions available on this device.
If you need to support this device, use different github issues to track it, describe the SN information and product details clearly, and solve the high CPU problem separately in the current issue to avoid confusing different problems and solving them together.

@wuwentao wuwentao added this to the 0.6.6 milestone Jan 3, 2025
@justmagic7211
Copy link
Author

@justmagic7211 修复cpu利用率以后,这台设备应该是没有任何支持的数据或功能可用。 如果需要支持这台设备,用不同的github issue跟踪吧,把SN信息,产品详情都描述清楚吧,当前issue单独解决high cpu的问题吧,避免各种不同的问题混淆在一起解决。

但是事实上这台设备可以控制,只是日志会发生那种情况

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@justmagic7211 After fixing the CPU utilization, there should be no supported data or functions available on this device. If you need to support this device, use different github issues to track it, describe the SN information and product details clearly, and solve the high CPU problem separately in the current issue to avoid confusing different problems and solving them together.

But in fact this device can be controlled, but what happens to the logs

@wuwentao
Copy link
Owner

wuwentao commented Jan 6, 2025

@justmagic7211 你可以控制? 那行吧,AC空调的传感器数据倒是不多,主要是控制。
我理解你这个设备应该取不到任何传感器数据,例如当前室内设置温度,当前工作模式等。
如果满足需求也行吧,倒是问题不大。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@justmagic7211 Can you control that? That's okay, the AC air conditioner doesn't have much sensor data, it's mainly about control.
I understand that your device should not be able to obtain any sensor data, such as the current indoor temperature setting, current working mode, etc.
It's okay if it meets the needs, but it's not a big problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants