Skip to content

Commit

Permalink
Merge pull request #1338 from custom-components/acconeer
Browse files Browse the repository at this point in the history
Use autosensors for Acconeer sensors
  • Loading branch information
Ernst79 authored Mar 29, 2024
2 parents 5c6cb87 + 8ba12bd commit 5e7b9a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 39 deletions.
38 changes: 6 additions & 32 deletions custom_components/ble_monitor/ble_parser/acconeer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

ACCONEER_SENSOR_IDS = {
0x80: "Acconeer XM122",
0x90: "Acconeer XM126 Distance",
0x90: "Acconeer XM126",
0x91: "Acconeer XM126",
}

MEASUREMENTS = {
0x80: ["presence", "temperature"],
0x90: ["distance_mm", "temperature"],
0x91: ["presence", "temperature"],
}


def parse_acconeer(self, data: bytes, mac: str):
"""Acconeer parser"""
Expand All @@ -31,48 +25,28 @@ def parse_acconeer(self, data: bytes, mac: str):
# Acconeer Sensors
device_type = ACCONEER_SENSOR_IDS[device_id]

if "Distance" in device_type:
measurements = MEASUREMENTS[device_id]
if device_id == 0x90:
(
battery_level,
temperature,
distance_mm,
reserved2
) = unpack("<HhHQ", xvalue)

if "distance_mm" in measurements:
result.update({
"distance mm": distance_mm,
})

if "temperature" in measurements:
result.update({
"temperature": temperature,
})

result.update({
"distance mm": distance_mm,
"temperature": temperature,
"battery": battery_level,
})
else:
measurements = MEASUREMENTS[device_id]
(
battery_level,
temperature,
presence,
reserved2
) = unpack("<HhHQ", xvalue)

if "presence" in measurements:
result.update({
"motion": 0 if presence == 0 else 1,
})

if "temperature" in measurements:
result.update({
"temperature": temperature,
})

result.update({
"motion": 0 if presence == 0 else 1,
"temperature": temperature,
"battery": battery_level,
})
else:
Expand Down
8 changes: 2 additions & 6 deletions custom_components/ble_monitor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,9 +1856,6 @@ class BLEMonitorBinarySensorEntityDescription(
'Meter TH S1' : [["temperature", "humidity", "battery", "rssi"], [], []],
'Meter TH plus' : [["temperature", "humidity", "battery", "rssi"], [], []],
'Laica Smart Scale' : [["weight", "impedance", "rssi"], [], []],
"Acconeer XM122" : [["temperature", "battery", "rssi"], [], ["motion"]],
"Acconeer XM126" : [["temperature", "battery", "rssi"], [], ["motion"]],
"Acconeer XM126 Distance" : [["temperature", "battery", "rssi"], ["distance mm"], []],
'K6 Sensor Beacon' : [["temperature", "humidity", "acceleration", "voltage", "battery", "rssi"], [], []],
'DSL-C08' : [["battery", "rssi", "voltage"], [], ["lock", "childlock"]],
'SmartDry cloth dryer' : [["temperature", "humidity", "voltage", "battery", "shake", "rssi"], [], ["switch"]],
Expand Down Expand Up @@ -1993,9 +1990,6 @@ class BLEMonitorBinarySensorEntityDescription(
'Meter TH S1' : 'Switchbot',
'Meter TH plus' : 'Switchbot',
'Laica Smart Scale' : 'Laica',
'Acconeer XM122' : 'Acconeer',
'Acconeer XM126' : 'Acconeer',
'Acconeer XM126 Distance' : 'Acconeer',
'K6 Sensor Beacon' : 'KKM',
'SmartDry cloth dryer' : 'SmartDry',
}
Expand Down Expand Up @@ -2030,6 +2024,8 @@ class BLEMonitorBinarySensorEntityDescription(

# Sensors that support automatic adding of sensors and binary sensors
AUTO_MANUFACTURER_DICT = {
'Acconeer XM122' : 'Acconeer',
'Acconeer XM126' : 'Acconeer',
'Amazfit Smart Scale' : 'Amazfit',
'Blustream' : 'Blustream',
'BTHome' : 'BTHome',
Expand Down
2 changes: 1 addition & 1 deletion custom_components/ble_monitor/test/test_acconeer_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_acconeer_xm126_distance(self):
sensor_msg, tracker_msg = ble_parser.parse_raw_data(data)

assert sensor_msg["firmware"] == "Acconeer"
assert sensor_msg["type"] == "Acconeer XM126 Distance"
assert sensor_msg["type"] == "Acconeer XM126"
assert sensor_msg["mac"] == "E00990B61234"
assert sensor_msg["packet"] == "6400160058050000000000000000"
assert sensor_msg["data"]
Expand Down

0 comments on commit 5e7b9a4

Please sign in to comment.