AlexxIT / SonoffLAN

Control Sonoff Devices with eWeLink (original) firmware over LAN and/or Cloud from Home Assistant
https://github.com/AlexxIT/Blog
MIT License
2.75k stars 416 forks source link

Exception on device discovery in DIY mode #1515

Open martink-p opened 3 weeks ago

martink-p commented 3 weeks ago

(At least) when in DIY mode an exception is raised due to a key error in the "device" dictionary: 2024-10-31 15:13:28.408 DEBUG (MainThread) [custom_components.sonoff.core.ewelink.local] 100214ec65 <= Local0 | Zeroconf error Traceback (most recent call last): File "/config/custom_components/sonoff/core/ewelink/local.py", line 135, in _handler2 self._handler3(deviceid, host, data) File "/config/custom_components/sonoff/core/ewelink/local.py", line 161, in _handler3 self.dispatcher_send(SIGNAL_UPDATE, msg) File "/config/custom_components/sonoff/core/ewelink/base.py", line 65, in dispatcher_send handler(*args, **kwargs) File "/config/custom_components/sonoff/core/ewelink/__init__.py", line 290, in local_update device["params"]["sledOnline"] = params["sledOnline"] KeyError: 'params'

I added some code above line 290 which fixed the issue. Due to the fact I'm not involved in the project, I'm not sure this is the correct set of variables and if it is the only location the fix is required.

if "params" not in device: device["params"] = params elif "sledOnline" in params: device["params"]["sledOnline"] = params["sledOnline"]

Please check my suggestion.