Skip to content

Commit

Permalink
feat: add support for TP357S (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: yoxcu <mick@yoxcu.de>
  • Loading branch information
bdraco and yoxcu authored Dec 6, 2023
1 parent 3c78e2f commit 78b0a05
Show file tree
Hide file tree
Showing 2 changed files with 168 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/thermopro_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _start_update(self, service_info: BluetoothServiceInfo) -> None:
return
if not service_info.manufacturer_data:
return
if len(list(service_info.manufacturer_data.values())[0]) != 4:
if len(list(service_info.manufacturer_data.values())[0]) < 4:
return
self.set_device_type(service_info.name.split(" ")[0])
self.set_title(f"{service_info.name} {short_address(service_info.address)}")
Expand All @@ -52,7 +52,7 @@ def _start_update(self, service_info: BluetoothServiceInfo) -> None:
+ changed_manufacturer_data[last_id]
)

if len(data) != 6:
if len(data) < 6:
return

(temp, humi) = UNPACK(data[1:4])
Expand Down
166 changes: 166 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,72 @@ def test_can_create():
source="local",
)

TP357_S = BluetoothServiceInfo(
name="TP357S (2142)",
manufacturer_data={
61122: b'\x00)"\x0b\x01',
},
service_uuids=[],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
service_data={},
source="local",
)


TP357_S_2 = BluetoothServiceInfo(
name="TP357S (2142)",
manufacturer_data={
61122: b'\x00)"\x0b\x01',
60866: b'\x00)"\x0b\x01',
60610: b'\x00)"\x0b\x01',
60354: b'\x00("\x0b\x01',
60098: b'\x00("\x0b\x01',
59842: b'\x00)"\x0b\x01',
59586: b'\x00("\x0b\x01',
59330: b'\x00("\x0b\x01',
59074: b'\x00("\x0b\x01',
58818: b'\x00("\x0b\x01',
58562: b"\x00'\"\x0b\x01",
58306: b'\x00("\x0b\x01',
58050: b'\x00("\x0b\x01',
57794: b'\x00)"\x0b\x01',
57538: b'\x00)"\x0b\x01',
57282: b'\x00)"\x0b\x01',
57026: b'\x00)"\x0b\x01',
56770: b'\x00)"\x0b\x01',
56514: b'\x00)"\x0b\x01',
56258: b'\x00)"\x0b\x01',
56002: b'\x00)"\x0b\x01',
55746: b'\x00*"\x0b\x01',
55490: b'\x00)"\x0b\x01',
55234: b'\x00*"\x0b\x01',
54978: b'\x00*"\x0b\x01',
54722: b'\x00*"\x0b\x01',
54466: b'\x00+"\x0b\x01',
54210: b'\x00-"\x0b\x01',
53954: b'\x00,"\x0b\x01',
53698: b'\x00/"\x0b\x01',
53442: b'\x001"\x0b\x01',
53186: b'\x00."\x0b\x01',
52930: b'\x00,"\x0b\x01',
52674: b'\x00,"\x0b\x01',
52418: b'\x00+"\x0b\x01',
52162: b'\x00*"\x0b\x01',
51906: b'\x00*"\x0b\x01',
51650: b'\x00*"\x0b\x01',
51394: b'\x00*"\x0b\x01',
51138: b'\x00*"\x0b\x01',
50882: b'\x00)"\x0b\x01',
},
service_uuids=[],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
service_data={},
source="local",
)


TP393 = BluetoothServiceInfo(
name="TP393 (9376)",
manufacturer_data={62146: b"\x005\x02,"},
Expand Down Expand Up @@ -159,6 +225,106 @@ def test_tp357():
)


def test_tp357s():
parser = ThermoProBluetoothDeviceData()
assert parser.update(TP357_S) == SensorUpdate(
title="TP357S (2142) EEFF",
devices={
None: SensorDeviceInfo(
name="TP357S (2142)",
model="TP357S",
manufacturer="ThermoPro",
sw_version=None,
hw_version=None,
)
},
entity_descriptions={
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="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="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,
),
},
entity_values={
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=23.8,
),
DeviceKey(key="humidity", device_id=None): SensorValue(
device_key=DeviceKey(key="humidity", device_id=None),
name="Humidity",
native_value=41,
),
DeviceKey(key="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
},
binary_entity_descriptions={},
binary_entity_values={},
)
assert parser.update(TP357_S_2) == SensorUpdate(
title="TP357S (2142) EEFF",
devices={
None: SensorDeviceInfo(
name="TP357S (2142)",
model="TP357S",
manufacturer="ThermoPro",
sw_version=None,
hw_version=None,
)
},
entity_descriptions={
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="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="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,
),
},
entity_values={
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=23.8,
),
DeviceKey(key="humidity", device_id=None): SensorValue(
device_key=DeviceKey(key="humidity", device_id=None),
name="Humidity",
native_value=41,
),
DeviceKey(key="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
},
binary_entity_descriptions={},
binary_entity_values={},
)


def test_tp357_add():
parser = ThermoProBluetoothDeviceData()
assert parser.update(TP357_ADD) == SensorUpdate(
Expand Down

0 comments on commit 78b0a05

Please sign in to comment.