Skip to content

Commit a04e13c

Browse files
authored
fix: model TC.x being detected as HT.w with active scans (#37)
1 parent d65b5ab commit a04e13c

File tree

2 files changed

+112
-4
lines changed

2 files changed

+112
-4
lines changed

src/sensorpush_ble/parser.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626
2: "TC.x",
2727
}
2828

29-
LOCAL_NAMES = ["HTP.xw", "HT.w", "TC.x"]
29+
LOCAL_NAMES = {
30+
"HTP.xw": "HTP.xw",
31+
"HT.w": "HT.w",
32+
"TC": "TC.x",
33+
"TC.x": "TC.x",
34+
}
3035

3136
SENSORPUSH_SERVICE_UUID_HT1 = "ef090000-11d6-42ba-93b8-9dd7ec090aa9"
3237
SENSORPUSH_SERVICE_UUID_V2 = "ef090000-11d6-42ba-93b8-9dd7ec090ab0"
@@ -148,10 +153,10 @@ def determine_device_type(
148153
if local_name == "s" and SENSORPUSH_SERVICE_UUID_HT1 in service_info.service_uuids:
149154
return "HT1"
150155

151-
device_type = None
152-
for match_name in LOCAL_NAMES:
156+
device_type: str | None = None
157+
for match_name, model_name in LOCAL_NAMES.items():
153158
if match_name in local_name:
154-
device_type = match_name
159+
device_type = model_name
155160

156161
if not device_type and SENSORPUSH_SERVICE_UUID_V2 in service_info.service_uuids:
157162
first_manufacturer_data_value_len = len(next(iter(manufacturer_data.values())))

tests/test_parser.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,3 +1639,106 @@ def test_tcx_overwriting_mfr_data():
16391639
),
16401640
},
16411641
)
1642+
1643+
1644+
def test_tc_detection_active_scans():
1645+
parser = SensorPushBluetoothDeviceData()
1646+
service_info = BluetoothServiceInfo(
1647+
name="SensorPush TC EEFF",
1648+
manufacturer_data={8: b"\x00\x00\x00"},
1649+
service_data={},
1650+
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
1651+
address="aa:bb:cc:dd:ee:ff",
1652+
rssi=-60,
1653+
source="local",
1654+
)
1655+
result = parser.update(service_info)
1656+
assert result == SensorUpdate(
1657+
title=None,
1658+
devices={
1659+
None: SensorDeviceInfo(
1660+
name="TC EEFF",
1661+
model="TC.x",
1662+
manufacturer="SensorPush",
1663+
sw_version=None,
1664+
hw_version=None,
1665+
)
1666+
},
1667+
entity_descriptions={
1668+
DeviceKey(key="temperature", device_id=None): SensorDescription(
1669+
device_key=DeviceKey(key="temperature", device_id=None),
1670+
device_class=SensorDeviceClass.TEMPERATURE,
1671+
native_unit_of_measurement=Units.TEMP_CELSIUS,
1672+
),
1673+
DeviceKey(key="signal_strength", device_id=None): SensorDescription(
1674+
device_key=DeviceKey(key="signal_strength", device_id=None),
1675+
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
1676+
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
1677+
),
1678+
},
1679+
entity_values={
1680+
DeviceKey(key="temperature", device_id=None): SensorValue(
1681+
device_key=DeviceKey(key="temperature", device_id=None),
1682+
name="Temperature",
1683+
native_value=-200.0,
1684+
),
1685+
DeviceKey(key="signal_strength", device_id=None): SensorValue(
1686+
device_key=DeviceKey(key="signal_strength", device_id=None),
1687+
name="Signal " "Strength",
1688+
native_value=-60,
1689+
),
1690+
},
1691+
binary_entity_descriptions={},
1692+
binary_entity_values={},
1693+
events={},
1694+
)
1695+
1696+
1697+
def test_tc_detection_active_scans_2():
1698+
parser = SensorPushBluetoothDeviceData()
1699+
service_info = BluetoothServiceInfo(
1700+
name="SensorPush TC EEFF",
1701+
manufacturer_data={59400: b"\r\x00\x00"},
1702+
service_data={},
1703+
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
1704+
address="aa:bb:cc:dd:ee:ff",
1705+
rssi=-60,
1706+
source="local",
1707+
)
1708+
result = parser.update(service_info)
1709+
assert result == SensorUpdate(
1710+
title=None,
1711+
devices={
1712+
None: SensorDeviceInfo(
1713+
name="TC EEFF",
1714+
model="TC.x",
1715+
manufacturer="SensorPush",
1716+
sw_version=None,
1717+
hw_version=None,
1718+
)
1719+
},
1720+
entity_descriptions={
1721+
DeviceKey(key="temperature", device_id=None): SensorDescription(
1722+
device_key=DeviceKey(key="temperature", device_id=None),
1723+
device_class=SensorDeviceClass.TEMPERATURE,
1724+
native_unit_of_measurement=Units.TEMP_CELSIUS,
1725+
),
1726+
DeviceKey(key="signal_strength", device_id=None): SensorDescription(
1727+
device_key=DeviceKey(key="signal_strength", device_id=None),
1728+
device_class=SensorDeviceClass.SIGNAL_STRENGTH,
1729+
native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
1730+
),
1731+
},
1732+
entity_values={
1733+
DeviceKey(key="signal_strength", device_id=None): SensorValue(
1734+
device_key=DeviceKey(key="signal_strength", device_id=None),
1735+
name="Signal " "Strength",
1736+
native_value=-60,
1737+
),
1738+
DeviceKey(key="temperature", device_id=None): SensorValue(
1739+
device_key=DeviceKey(key="temperature", device_id=None),
1740+
name="Temperature",
1741+
native_value=22.5,
1742+
),
1743+
},
1744+
)

0 commit comments

Comments
 (0)