Skip to content

Commit

Permalink
Add more binary sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernst79 committed Sep 23, 2023
1 parent a963c94 commit ba0c841
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 2 deletions.
4 changes: 2 additions & 2 deletions custom_components/ble_monitor/ble_parser/bthome_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class MeasTypes:
meas_format="garage_door",
),
0x1C: MeasTypes(
meas_format="gas",
meas_format="gas_detected",
),
0x1D: MeasTypes(
meas_format="heat",
Expand All @@ -156,7 +156,7 @@ class MeasTypes:
meas_format="lock",
),
0x20: MeasTypes(
meas_format="moisture",
meas_format="moisture_detected",
),
0x21: MeasTypes(
meas_format="motion",
Expand Down
40 changes: 40 additions & 0 deletions custom_components/ble_monitor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,42 @@ class BLEMonitorBinarySensorEntityDescription(
device_class=BinarySensorDeviceClass.CONNECTIVITY,
force_update=True,
),
BLEMonitorBinarySensorEntityDescription(
key="garage_door",
sensor_class="BaseBinarySensor",
update_behavior="Instantly",
name="garage door",
unique_id="bgdr_",
device_class=BinarySensorDeviceClass.GARAGE_DOOR,
force_update=True,
),
BLEMonitorBinarySensorEntityDescription(
key="gas_detected",
sensor_class="BaseBinarySensor",
update_behavior="Instantly",
name="gas",
unique_id="bgas_",
device_class=BinarySensorDeviceClass.GAS,
force_update=True,
),
BLEMonitorBinarySensorEntityDescription(
key="heat",
sensor_class="BaseBinarySensor",
update_behavior="Instantly",
name="heat",
unique_id="bheat_",
device_class=BinarySensorDeviceClass.HEAT,
force_update=True,
),
BLEMonitorBinarySensorEntityDescription(
key="moisture_detected",
sensor_class="BaseBinarySensor",
update_behavior="Instantly",
name="moisture",
unique_id="bmoist_",
device_class=BinarySensorDeviceClass.MOISTURE,
force_update=True,
),
BLEMonitorBinarySensorEntityDescription(
key="binary",
sensor_class="BaseBinarySensor",
Expand Down Expand Up @@ -1543,10 +1579,14 @@ class BLEMonitorBinarySensorEntityDescription(
"binary",
"door",
"dropping",
"garage_door",
"gas_detected",
"heat",
"impact",
"light",
"lock",
"motion",
"moisture_detected"
"opening",
"smoke",
"switch",
Expand Down
119 changes: 119 additions & 0 deletions custom_components/ble_monitor/test/test_bthome_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,125 @@ def test_bthome_v2_connectivity(self):
assert sensor_msg["connectivity"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_door(self):
"""Test BTHome parser for door measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401A01CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["door"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_garage_door(self):
"""Test BTHome parser for garage door measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401B01CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["garage_door"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_gas_detected(self):
"""Test BTHome parser for gas detected measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401C00CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["gas_detected"] == 0
assert sensor_msg["rssi"] == -52

def test_bthome_v2_heat(self):
"""Test BTHome parser for heat measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401D01CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["heat"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_light(self):
"""Test BTHome parser for light measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401E01CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["light"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_lock(self):
"""Test BTHome parser for lock measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401F01CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["lock"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_moisture_detected(self):
"""Test BTHome parser for moisture detected measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC401F01CC"
data = bytes(bytearray.fromhex(data_string))

# pylint: disable=unused-variable
ble_parser = BleParser()
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "BTHome V2"
assert sensor_msg["type"] == "BTHome"
assert sensor_msg["mac"] == "5448E68F80A5"
assert sensor_msg["packet"] == "no packet id"
assert sensor_msg["data"]
assert sensor_msg["moisture_detected"] == 1
assert sensor_msg["rssi"] == -52

def test_bthome_v2_button(self):
"""Test BTHome parser for button sensor measurement"""
data_string = "043E1602010000A5808FE648540A0201060616D2FC403A02CC"
Expand Down

0 comments on commit ba0c841

Please sign in to comment.