Skip to content

Commit

Permalink
Update support Mi Body Composition Scale S400 #1388
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Nov 26, 2024
1 parent 7bf2962 commit c197e8d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def decode(self, device: "XDevice", payload: dict, data: str):
class BLEScaleS400(BaseConv):
def decode(self, device: "XDevice", payload: dict, value: int):
weight = value & 0x7FF
heart_rate = (value >> 11) & 0xFF
heart_rate = (value >> 11) & 0x7F
impedance = value >> 18
if weight != 0:
payload["weight"] = weight / 10
Expand Down
4 changes: 3 additions & 1 deletion custom_components/xiaomi_gateway3/core/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2018,13 +2018,15 @@
]
}, {
# https://home.miot-spec.com/spec/yunmai.scales.ms107
18639: ["Xiaomi", "Body Composition Scale S400", "BHR7793GL", "yunmai.scales.ms103"],
12505: ["Xiaomi", "Body Composition Scale S400", "MJTZC01YM", "BHR7026CN", "yunmai.scales.ms103"],
18639: ["Xiaomi", "Body Composition Scale S400 Blue", "MJTZC01YM", "yunmai.scales.ms107"],
"spec": [
BaseConv("weight", "sensor", entity={"icon": "mdi:human", "units": "kg"}),
BaseConv("heart_rate", "sensor", entity={"icon": "mdi:heart-pulse", "units": "bpm"}),
BaseConv("impedance_low", "sensor", entity={"icon": "mdi:omega", "units": "ohm"}),
BaseConv("impedance_high", "sensor", entity={"icon": "mdi:omega", "units": "ohm"}),
BLEScaleS400("raw_data", mi="11.e.1022.p.2"),
BaseConv("timestamp", mi="11.e.1022.p.3"),
],
}, {
# https://home.miot-spec.com/spec/izq.sensor_occupy.ble
Expand Down
9 changes: 2 additions & 7 deletions tests/test_conv_ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,6 @@ def test_18639():
assert p == {"impedance_low": 471.1}

p = device.decode(
{"siid": 11, "eiid": 1022, "arguments": [{"piid": 2, "value": 1343068894}]}
{"siid": 11, "eiid": 1022, "arguments": [{"piid": 2, "value": 1174444720}]}
)
assert p == {"impedance_high": 512.3, "weight": 73.4}

p = device.decode(
{"siid": 11, "eiid": 1022, "arguments": [{"piid": 2, "value": 1240727552}]}
)
assert p == {"impedance_low": 473.3}
assert p == {"heart_rate": 69, "impedance_high": 448.0, "weight": 68.8}

0 comments on commit c197e8d

Please sign in to comment.