kizniche / Mycodo

An environmental monitoring and regulation system
http://kylegabriel.com/projects/
GNU General Public License v3.0
2.95k stars 494 forks source link

Fix for Kasa plugs in on_off_kasa_plugs.py #1221

Closed peschler closed 2 years ago

peschler commented 2 years ago

Hi there, i think i have fixed a bug with Kasa plugs which did not work for me. When creating a "[IP] On/Off: Kasa WiFi Power Plug" output, configuring it always failed with a daemon connection timeout. No useful info in the logs, especially no loggging output from the output module. So I examined the module code and there's a simple fix.

The "aio_rpc_server" thread is passed four arguments in line 176/177, but the "aio_rpc_server()" function only uses/accepts three arguments. This results in the rpc server to not start at all and leaving no log error whatsoever. The output setup will fail and a Kasa plugs cannot be controlled. By adding a fourth argument "channel_count" the rpc server is started correctly and the output module for Kasa plugs is working fine. It should be noted that new argument is never used but turning on/off the plugs works fine.

I am using and have tested this with two Kasa Plugs KP105. Mycodo Version: 8.14.1 Python Version: 3.9.2 python-kasa 0.5.0

kizniche commented 2 years ago

Excellent! Thanks for figuring this out. This issue is the result of refactoring the multi-channel kasa Mycodo module for use with the single-channel plugs, but I must have missed this. The entire argument can actually be removed since it's not used (there is only one channel).

kizniche commented 2 years ago

committed the removal (commit above).

kizniche commented 2 years ago

This pull request has been mentioned on Radical DIY Forum. There might be relevant details there:

https://forum.radicaldiy.com/t/mycodo-v8-14-0-release/1136/3