Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding the new 2023 "Pro Check Universal" device (M1017020A) #9

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/mopeka_iot_ble/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,18 @@ class MopekaDevice:

DEVICE_TYPES = {
0x3: MopekaDevice("M1017", "Pro Check", 10),
0xC: MopekaDevice("M1017", "Pro Check Universal", 10),
0x4: MopekaDevice("", "Top down air space", 10),
0x5: MopekaDevice("", "Bottom up water", 10),
0x8: MopekaDevice("M1015", "Pro Plus", 10),
}

SUPPORTED_DEVICE_TYPES = {0x3, 0x8}
SUPPORTED_DEVICE_TYPES = {0x3, 0xC, 0x8}


def hex(data: bytes) -> str:
"""Return a string object containing two hexadecimal digits for each byte in the instance."""
return "b'{}'".format("".join(f"\\x{b:02x}" for b in data))
return "b'{}'".format("".join(f"\\x{b:02x}" for b in data)) # noqa: E231


def battery_to_voltage(battery: int) -> float:
Expand Down
137 changes: 137 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@
)


CHECK_UNIVERSAL_INSTALLED_SERVICE_INFO = BluetoothServiceInfo(
name="",
address="C9:F3:32:E0:F5:09",
rssi=-63,
manufacturer_data={89: b"\x0CpC\xb6\xc3\xe0\xf5\t\xfa\xe3"},
service_uuids=["0000fee5-0000-1000-8000-00805f9b34fb"],
service_data={},
source="local",
)


def test_hex():
assert (
hex(b"\x08rF\x000\xe0\xf5\t\xf0\xd8")
Expand Down Expand Up @@ -580,6 +591,132 @@ def test_pro_installed():
)


def test_check_universal_installed():
parser = MopekaIOTBluetoothDeviceData()
service_info = CHECK_UNIVERSAL_INSTALLED_SERVICE_INFO
result = parser.update(service_info)
assert result == SensorUpdate(
title=None,
devices={
None: SensorDeviceInfo(
name="Pro Check Universal F509",
model="M1017",
manufacturer="Mopeka IOT",
sw_version=None,
hw_version=None,
)
},
entity_descriptions={
DeviceKey(key="battery_voltage", device_id=None): SensorDescription(
device_key=DeviceKey(key="battery_voltage", device_id=None),
device_class=SensorDeviceClass.VOLTAGE,
native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT,
),
DeviceKey(key="tank_level", device_id=None): SensorDescription(
device_key=DeviceKey(key="tank_level", device_id=None),
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement=Units.LENGTH_MILLIMETERS,
),
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="battery", device_id=None): SensorDescription(
device_key=DeviceKey(key="battery", device_id=None),
device_class=SensorDeviceClass.BATTERY,
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,
),
DeviceKey(key="reading_quality", device_id=None): SensorDescription(
device_key=DeviceKey(key="reading_quality", device_id=None),
device_class=None,
native_unit_of_measurement=Units.PERCENTAGE,
),
DeviceKey(key="reading_quality_raw", device_id=None): SensorDescription(
device_key=DeviceKey(key="reading_quality_raw", device_id=None),
device_class=None,
native_unit_of_measurement=None,
),
DeviceKey(key="accelerometer_y", device_id=None): SensorDescription(
device_key=DeviceKey(key="accelerometer_y", device_id=None),
device_class=None,
native_unit_of_measurement=None,
),
DeviceKey(key="accelerometer_x", device_id=None): SensorDescription(
device_key=DeviceKey(key="accelerometer_x", device_id=None),
device_class=None,
native_unit_of_measurement=None,
),
},
entity_values={
DeviceKey(key="battery_voltage", device_id=None): SensorValue(
device_key=DeviceKey(key="battery_voltage", device_id=None),
name="Battery " "Voltage",
native_value=3.5,
),
DeviceKey(key="tank_level", device_id=None): SensorValue(
device_key=DeviceKey(key="tank_level", device_id=None),
name="Tank " "Level",
native_value=341,
),
DeviceKey(key="temperature", device_id=None): SensorValue(
device_key=DeviceKey(key="temperature", device_id=None),
name="Temperature",
native_value=27,
),
DeviceKey(key="battery", device_id=None): SensorValue(
device_key=DeviceKey(key="battery", device_id=None),
name="Battery",
native_value=100,
),
DeviceKey(key="signal_strength", device_id=None): SensorValue(
device_key=DeviceKey(key="signal_strength", device_id=None),
name="Signal " "Strength",
native_value=-63,
),
DeviceKey(key="reading_quality", device_id=None): SensorValue(
device_key=DeviceKey(key="reading_quality", device_id=None),
name="Reading " "quality",
native_value=100,
),
DeviceKey(key="reading_quality_raw", device_id=None): SensorValue(
device_key=DeviceKey(key="reading_quality_raw", device_id=None),
name="Reading " "quality " "raw",
native_value=3,
),
DeviceKey(key="accelerometer_y", device_id=None): SensorValue(
device_key=DeviceKey(key="accelerometer_y", device_id=None),
name="Position " "Y",
native_value=227,
),
DeviceKey(key="accelerometer_x", device_id=None): SensorValue(
device_key=DeviceKey(key="accelerometer_x", device_id=None),
name="Position " "X",
native_value=250,
),
},
binary_entity_descriptions={
DeviceKey(key="button_pressed", device_id=None): BinarySensorDescription(
device_key=DeviceKey(key="button_pressed", device_id=None),
device_class=BinarySensorDeviceClass.OCCUPANCY,
)
},
binary_entity_values={
DeviceKey(key="button_pressed", device_id=None): BinarySensorValue(
device_key=DeviceKey(key="button_pressed", device_id=None),
name="Button pressed",
native_value=False,
)
},
events={},
)


def test_check_installed():
parser = MopekaIOTBluetoothDeviceData()
service_info = CHECK_INSTALLED_SERVICE_INFO
Expand Down