Skip to content

Commit

Permalink
feat: add support for cgp23w (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 authored Dec 16, 2023
1 parent 4eed280 commit ac9fa97
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/qingping_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ class QingpingDevice:
0x04: QingpingDevice("CGH1", "Door/Window Sensor"), # Door/Window Sensor
0x07: QingpingDevice("CGG1", ""),
0x09: QingpingDevice("CGP1W", ""),
0x0C: QingpingDevice("CGD1", "Alarm Clock"),
0x0E: QingpingDevice("CGDN1", "Air Monitor Lite"),
0x0F: QingpingDevice("CGM1", "Lee Guitars Thermo-Hygrometer"),
0x12: QingpingDevice("CGPR1", "Motion & Light"),
0x15: QingpingDevice("CGF1W", "Temp RH Pro E"),
0x16: QingpingDevice("CGG1", "Temp RH M"),
0x12: QingpingDevice("CGPR1", "Motion & Light"),
0x18: QingpingDevice("CGP23W", "Temp & RH Monitor Pro"),
0x1E: QingpingDevice("CGC1", "BT Clock Lite"),
0x0C: QingpingDevice("CGD1", "Alarm Clock"),
0x0E: QingpingDevice("CGDN1", "Air Monitor Lite"),
0x24: QingpingDevice("CGDN1", "Air Monitor Lite"),
0x0F: QingpingDevice("CGM1", "Lee Guitars Thermo-Hygrometer"),
}


Expand Down Expand Up @@ -98,17 +99,6 @@ def _process_xdata(self, xdata_id: int, xdata_size: int, xdata: bytes) -> None:
elif xdata_id == 0x02 and xdata_size == 1:
batt = unpack("B", xdata)[0]
self.update_predefined_sensor(SensorLibrary.BATTERY__PERCENTAGE, batt)
elif xdata_id == 0x07 and xdata_size == 2:
pressure = unpack("<H", xdata)[0]
self.update_predefined_sensor(SensorLibrary.PRESSURE__MBAR, pressure / 10)
elif xdata_id == 0x08 and xdata_size == 4:
(motion, illuminance_1, illuminance_2) = unpack("<BHB", xdata)
self.update_predefined_binary_sensor(
BinarySensorDeviceClass.MOTION, bool(motion)
)
self.update_predefined_sensor(
SensorLibrary.LIGHT__LIGHT_LUX, illuminance_1 + illuminance_2
)
elif xdata_id == 0x04 and xdata_size == 1:
closed = unpack("B", xdata)[0]
self.update_predefined_binary_sensor(
Expand All @@ -120,6 +110,17 @@ def _process_xdata(self, xdata_id: int, xdata_size: int, xdata: bytes) -> None:
key=(None, "door_left_open"),
name="Door left open",
)
elif xdata_id == 0x07 and xdata_size == 2:
pressure = unpack("<H", xdata)[0]
self.update_predefined_sensor(SensorLibrary.PRESSURE__MBAR, pressure / 10)
elif xdata_id == 0x08 and xdata_size == 4:
(motion, illuminance_1, illuminance_2) = unpack("<BHB", xdata)
self.update_predefined_binary_sensor(
BinarySensorDeviceClass.MOTION, bool(motion)
)
self.update_predefined_sensor(
SensorLibrary.LIGHT__LIGHT_LUX, illuminance_1 + illuminance_2
)
elif xdata_id == 0x09 and xdata_size == 4:
illuminance = unpack("<I", xdata)[0]
self.update_predefined_sensor(SensorLibrary.LIGHT__LIGHT_LUX, illuminance)
Expand Down
87 changes: 87 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,20 @@ def test_can_create():
)


QINGPING_TEMP_RH_MONITOR_PRO = BluetoothServiceInfo(
name="Qingping Temp & RH Monitor Pro",
manufacturer_data={},
service_uuids=[],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
service_data={
"0000fdcd-0000-1000-8000-00805f9b34fb": b"\x88\x18\x07\x22\x40\x34\x2d\x58\x01\x04\x18\x01\xcd"
b"\x00\x02\x01\x61\x07\x02\x73\x27"
},
source="local",
)


def test_supported_motion_and_light():
parser = QingpingBluetoothDeviceData()
parser.supported(MOTION_AND_LIGHT_ENSURE_SUPPORTED) is True
Expand Down Expand Up @@ -924,3 +938,76 @@ def test_temp_rh_pro_e():
binary_entity_descriptions={},
binary_entity_values={},
)


def test_temp_rh_monitor_pro():
parser = QingpingBluetoothDeviceData()
parsed = parser.update(QINGPING_TEMP_RH_MONITOR_PRO)
assert parsed == SensorUpdate(
title="Temp & RH Monitor Pro EEFF",
devices={
None: SensorDeviceInfo(
name="Temp & RH Monitor Pro EEFF",
model="CGP23W",
manufacturer="Qingping",
sw_version=None,
hw_version=None,
)
},
entity_descriptions={
DeviceKey(key="humidity", device_id=None): SensorDescription(
device_key=DeviceKey(key="humidity", device_id=None),
device_class=SensorDeviceClass.HUMIDITY,
native_unit_of_measurement=Units.PERCENTAGE,
),
DeviceKey(key="temperature", device_id=None): SensorDescription(
device_key=DeviceKey(key="temperature", device_id=None),
device_class=SensorDeviceClass.TEMPERATURE,
native_unit_of_measurement=Units.TEMP_CELSIUS,
),
DeviceKey(key="pressure", device_id=None): SensorDescription(
device_key=DeviceKey(key="pressure", device_id=None),
device_class=SensorDeviceClass.PRESSURE,
native_unit_of_measurement=Units.PRESSURE_MBAR,
),
DeviceKey(key="signal_strength", device_id=None): SensorDescription(
device_key=DeviceKey(key="signal_strength", device_id=None),
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
),
DeviceKey(key="battery", device_id=None): SensorDescription(
device_key=DeviceKey(key="battery", device_id=None),
device_class=SensorDeviceClass.BATTERY,
native_unit_of_measurement=Units.PERCENTAGE,
),
},
entity_values={
DeviceKey(key="humidity", device_id=None): SensorValue(
device_key=DeviceKey(key="humidity", device_id=None),
name="Humidity",
native_value=20.5,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=28.0,
),
DeviceKey(key="pressure", device_id=None): SensorValue(
device_key=DeviceKey(key="pressure", device_id=None),
name="Pressure",
native_value=1009.9,
),
DeviceKey(key="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="battery", device_id=None): SensorValue(
device_key=DeviceKey(key="battery", device_id=None),
name="Battery",
native_value=97,
),
},
binary_entity_descriptions={},
binary_entity_values={},
)

0 comments on commit ac9fa97

Please sign in to comment.