Skip to content

Commit

Permalink
Scale binary energy values by an additional factor of 10 (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
mill1000 authored Dec 11, 2024
1 parent 12493fa commit 45828d2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion msmart/device/AC/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1024,10 +1024,11 @@ def parse_energy(d: bytes) -> tuple[float, float]:
100 * decode_bcd(d[1]) +
1 * decode_bcd(d[2]) +
0.01 * decode_bcd(d[3]))
# Scale binary energy by an extra power of 10. See mill1000/midea-msmart#174
binary = ((d[0] << 24) +
(d[1] << 16) +
(d[2] << 8) +
d[3]) / 10
d[3]) / 100
return bcd, binary

def parse_power(d: bytes) -> tuple[float, float]:
Expand Down
2 changes: 1 addition & 1 deletion msmart/device/AC/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def test_binary_energy_usage(self) -> None:
"""Test we decode binary energy usage responses correctly."""
TEST_RESPONSES = {
# https://github.com/mill1000/midea-ac-py/issues/204#issuecomment-2314705021
(150.4, .6, 279.5): bytes.fromhex("aa22ac00000000000803c1210144000005e00000000000000006000aeb000000487a5e"),
(15.04, .06, 279.5): bytes.fromhex("aa22ac00000000000803c1210144000005e00000000000000006000aeb000000487a5e"),

# https://github.com/mill1000/midea-msmart/pull/116#issuecomment-2218753545
(None, None, None): bytes.fromhex("aa20ac00000000000303c1210144000000000000000000000000000000000843bc"),
Expand Down
2 changes: 1 addition & 1 deletion msmart/device/AC/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_binary_energy_usage_response(self) -> None:
"""Test parsing of EnergyUsageResponses into device state with binary format."""
TEST_RESPONSES = {
# https://github.com/mill1000/midea-ac-py/issues/204#issuecomment-2314705021
(150.4, .6, 279.5): bytes.fromhex("aa22ac00000000000803c1210144000005e00000000000000006000aeb000000487a5e"),
(15.04, .06, 279.5): bytes.fromhex("aa22ac00000000000803c1210144000005e00000000000000006000aeb000000487a5e"),

# https://github.com/mill1000/midea-msmart/pull/116#issuecomment-2218753545
(None, None, None): bytes.fromhex("aa20ac00000000000303c1210144000000000000000000000000000000000843bc"),
Expand Down

0 comments on commit 45828d2

Please sign in to comment.