Skip to content

Commit

Permalink
fix: handle jagged stairstep for LYWSD03MMC humidity (#73)
Browse files Browse the repository at this point in the history
* fix: handle jagged stairstep for LYWSD03MMC humidity
  • Loading branch information
apaperclip authored Mar 10, 2024
1 parent 7fb8287 commit efb3229
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/xiaomi_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,18 @@ def obj1006(
"""Humidity"""
if len(xobj) == 2:
(humi,) = H_STRUCT.unpack(xobj)
device.update_predefined_sensor(SensorLibrary.HUMIDITY__PERCENTAGE, humi / 10)
if device_type in ["LYWSD03MMC", "MHO-C401"]:
# To handle jagged stair stepping readings from these sensors.
# https://github.com/custom-components/ble_monitor/blob/ef2e3944b9c1a635208390b8563710d0eec2a945/custom_components/ble_monitor/sensor.py#L752
# https://github.com/esphome/esphome/blob/c39f6d0738d97ecc11238220b493731ec70c701c/esphome/components/xiaomi_lywsd03mmc/xiaomi_lywsd03mmc.cpp#L44C14-L44C99
# https://github.com/custom-components/ble_monitor/issues/7#issuecomment-595948254
device.update_predefined_sensor(
SensorLibrary.HUMIDITY__PERCENTAGE, int(humi / 10)
)
else:
device.update_predefined_sensor(
SensorLibrary.HUMIDITY__PERCENTAGE, humi / 10
)
return {}


Expand Down
2 changes: 1 addition & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ def test_Xiaomi_LYWSD03MMC_encrypted():
},
entity_values={
KEY_HUMIDITY: SensorValue(
name="Humidity", device_key=KEY_HUMIDITY, native_value=46.7
name="Humidity", device_key=KEY_HUMIDITY, native_value=46
),
KEY_SIGNAL_STRENGTH: SensorValue(
name="Signal Strength", device_key=KEY_SIGNAL_STRENGTH, native_value=-60
Expand Down

0 comments on commit efb3229

Please sign in to comment.