Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion switchbot/adv_parsers/presence_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ def process_presence_sensor(
motion_detected = bool(mfr_data[7] & 0x40)
battery_bits = (mfr_data[7] >> 2) & 0x03
battery_range = BATTERY_LEVEL_MAP.get(battery_bits, "Unknown")
duration = (mfr_data[8] << 8) + mfr_data[9]
trigger_flag = mfr_data[10]
led_state = bool(mfr_data[11] & 0x80)
light_level = mfr_data[11] & 0x0F
light_level = mfr_data[11] & 0x1F

result = {
"sequence_number": seq_number,
"adaptive_state": adaptive_state,
"motion_detected": motion_detected,
"battery_range": battery_range,
"duration": duration,
"trigger_flag": trigger_flag,
"led_state": led_state,
"lightLevel": light_level,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_adv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3508,6 +3508,7 @@ def test_humidifer_with_empty_data() -> None:
"adaptive_state": True,
"battery": 100,
"battery_range": ">=60%",
"duration": 1110,
"led_state": True,
"lightLevel": 12,
"motion_detected": True,
Expand Down Expand Up @@ -3805,6 +3806,7 @@ def test_adv_active(test_case: AdvTestCase) -> None:
{
"adaptive_state": True,
"battery_range": ">=60%",
"duration": 1110,
"led_state": True,
"lightLevel": 12,
"motion_detected": True,
Expand Down