Skip to content

Commit

Permalink
Fix bug in local response from AltoBeam GTWS78 #1160
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Oct 15, 2023
1 parent 963833c commit 74cd74c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions custom_components/sonoff/core/ewelink/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,6 @@ def decrypt_msg(msg: dict, devicekey: str = None) -> dict:
# Fix Sonoff RF Bridge sintax bug
if data and data.startswith(b'{"rf'):
data = data.replace(b'"="', b'":"')
# fix https://github.com/AlexxIT/SonoffLAN/issues/1160
data = data.rstrip(b"\x02")
return json.loads(data)
13 changes: 12 additions & 1 deletion tests/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from custom_components.sonoff.core.ewelink import XDevice, XRegistry
from custom_components.sonoff.core.ewelink import XDevice, XRegistry, XRegistryLocal
from . import save_to


Expand Down Expand Up @@ -36,3 +36,14 @@ def test_bulk():
assert registry_send[0][1] == {
"switches": [{"outlet": 1, "switch": "on"}, {"outlet": 2, "switch": "off"}]
}


def test_issue_1160():
payload = XRegistryLocal.decrypt_msg(
{
"iv": "MTA4MDc1MTQ5NzE5ODE2Ng==",
"data": "D85ho6GLI5uFX2b1+vohUIb+Xt99f55wxsBsNhqpPQdQ/WNc3ZTlCi1UVFiFU5cnaCPjvXPG6pqfHqXdtCO2fA==",
},
"9b0810bc-557a-406c-8266-614767890531",
)
assert payload == {"switches": [{"outlet": 0, "switch": "off"}]}

0 comments on commit 74cd74c

Please sign in to comment.