Skip to content

Commit

Permalink
Add support for reading the co2 value from meter pro
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Oct 22, 2024
1 parent eec843f commit 5ab93eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions switchbot/adv_parsers/meter.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""Meter parser."""
from __future__ import annotations

from typing import Any
import struct
from typing import Any, Optional

CO2_UNPACK = struct.Struct(">H").unpack_from


def process_wosensorth(data: bytes | None, mfr_data: bytes | None) -> dict[str, Any]:
"""Process woSensorTH/Temp sensor services data."""
temp_data = None
battery = None
temp_data: bytes | None = None
battery: bytes | None = None

if mfr_data:
temp_data = mfr_data[8:11]
Expand Down Expand Up @@ -45,11 +48,13 @@ def process_wosensorth(data: bytes | None, mfr_data: bytes | None) -> dict[str,

def process_wosensorth_c(data: bytes | None, mfr_data: bytes | None) -> dict[str, Any]:
"""Process woSensorTH/Temp sensor services data with CO2."""
temp_data = None
battery = None
temp_data: bytes | None = None
battery: bytes | None = None
co2_data: bytes | None

if mfr_data:
temp_data = mfr_data[8:11]
co2_data = mfr_data[13:15]

if data:
if not temp_data:
Expand Down Expand Up @@ -79,4 +84,7 @@ def process_wosensorth_c(data: bytes | None, mfr_data: bytes | None) -> dict[str
"battery": battery,
}

if co2_data:
_wosensorth_data["co2"] = CO2_UNPACK(co2_data)[0]

return _wosensorth_data
2 changes: 2 additions & 0 deletions tests/test_adv_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,7 @@ def test_meter_pro_c_active() -> None:
"humidity": 36,
"temp": {"c": 27.7, "f": 81.86},
"temperature": 27.7,
"co2": 725,
},
"isEncrypted": False,
"model": "5",
Expand Down Expand Up @@ -1671,6 +1672,7 @@ def test_meter_pro_c_passive() -> None:
"humidity": 36,
"temp": {"c": 27.7, "f": 81.86},
"temperature": 27.7,
"co2": 725,
},
"isEncrypted": False,
"model": "5",
Expand Down

0 comments on commit 5ab93eb

Please sign in to comment.