Skip to content

Commit

Permalink
feat: add support for TC.x (#33)
Browse files Browse the repository at this point in the history
Co-authored-by: James Nick Sears <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 22, 2024
1 parent 37b7c3e commit 3279892
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/sensorpush_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@

_LOGGER = logging.getLogger(__name__)

SENSORPUSH_DEVICE_TYPES = {1: "HT1", 64: "HTP.xw", 65: "HT.w"}
SENSORPUSH_DEVICE_TYPES = {1: "HT1", 64: "HTP.xw", 65: "HT.w", 66: "TC.x"}

SENSORPUSH_MANUFACTURER_DATA_LEN = {
3: "HT.w",
5: "HTP.xw",
2: "TC.x",
}

LOCAL_NAMES = ["HTP.xw", "HT.w"]
LOCAL_NAMES = ["HTP.xw", "HT.w", "TC.x"]

SENSORPUSH_SERVICE_UUID_HT1 = "ef090000-11d6-42ba-93b8-9dd7ec090aa9"
SENSORPUSH_SERVICE_UUID_V2 = "ef090000-11d6-42ba-93b8-9dd7ec090ab0"

SENSORPUSH_PACK_PARAMS = {
64: [[-40.0, 140.0, 0.0025], [0.0, 100.0, 0.0025], [30000.0, 125000.0, 1.0]],
65: [[-40.0, 125.0, 0.0025], [0.0, 100.0, 0.0025]],
66: [[-200.0, 1800.0, 0.0625]],
}

SENSORPUSH_DATA_TYPES = {
Expand All @@ -43,6 +45,7 @@
SensorLibrary.PRESSURE__MBAR,
],
65: [SensorLibrary.TEMPERATURE__CELSIUS, SensorLibrary.HUMIDITY__PERCENTAGE],
66: [SensorLibrary.TEMPERATURE__CELSIUS],
}


Expand Down
241 changes: 241 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1398,3 +1398,244 @@ def test_ht1_large_data_set():
),
},
)


def test_tcx():
parser = SensorPushBluetoothDeviceData()
service_info = BluetoothServiceInfo(
name="SensorPush TC.x EEFF",
manufacturer_data={63752: b"\r\x00\x00"},
service_data={},
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
source="local",
)
result = parser.update(service_info)
assert result == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="TC.x EEFF",
model="TC.x",
manufacturer="SensorPush",
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="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="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=23.56,
),
},
)


def test_tcx_overwriting_mfr_data():
parser = SensorPushBluetoothDeviceData()
service_info = BluetoothServiceInfo(
name="SensorPush TC.x EEFF",
manufacturer_data={59400: b"\r\x00\x00"},
service_data={},
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
source="local",
)
result = parser.update(service_info)
assert result == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="TC.x EEFF",
model="TC.x",
manufacturer="SensorPush",
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="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="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=22.5,
),
},
)

service_info_2 = BluetoothServiceInfo(
name="SensorPush TC.x EEFF",
manufacturer_data={59400: b"\r\x00\x00", 63752: b"\r\x03\x00"},
service_data={},
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
source="local",
)
result_2 = parser.update(service_info_2)
assert result_2 == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="TC.x EEFF",
model="TC.x",
manufacturer="SensorPush",
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="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="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=311.19,
),
},
)

service_info_3 = BluetoothServiceInfo(
name="SensorPush TC.x EEFF",
manufacturer_data={59400: b"\r\x00\x00", 63752: b"\r\x01\x00"},
service_data={},
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
source="local",
)
result_3 = parser.update(service_info_3)
assert result_3 == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="TC.x EEFF",
model="TC.x",
manufacturer="SensorPush",
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="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="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=119.44,
),
},
)

service_info_3 = BluetoothServiceInfo(
name="SensorPush TC.x EEFF",
manufacturer_data={59400: b"\r\x00\x00", 63752: b"\r\x02\x00"},
service_data={},
service_uuids=["ef090000-11d6-42ba-93b8-9dd7ec090ab0"],
address="aa:bb:cc:dd:ee:ff",
rssi=-60,
source="local",
)
result_3 = parser.update(service_info_3)
assert result_3 == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="TC.x EEFF",
model="TC.x",
manufacturer="SensorPush",
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="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="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-60,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=215.31,
),
},
)

0 comments on commit 3279892

Please sign in to comment.