Skip to content

Commit 6e6bed8

Browse files
authored
Merge branch 'master' into xm126_merge_fix
2 parents 293c3a7 + 1482f8d commit 6e6bed8

File tree

109 files changed

+1242
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1242
-710
lines changed

.github/workflows/pre-commit.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ name: pre-commit
33
on:
44
pull_request:
55
push:
6-
branches: [main]
6+
branches: [master]
77

88
jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
1313
- uses: actions/setup-python@v5
14-
- uses: pre-commit/[email protected].0
14+
- uses: pre-commit/[email protected].1

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ This custom component for [Home Assistant](https://www.home-assistant.io) passiv
3232
- Blustream (Taylor TaylorSense, D'Addario Humiditrak)
3333
- BTHome
3434
- b-parasite
35+
- Chef iQ
3536
- Ela
3637
- Govee
3738
- Grundfos

custom_components/ble_monitor/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ async def service_parse_data(service_call):
176176

177177
_LOGGER.debug("Initializing BLE Monitor integration (YAML): %s", CONFIG_YAML)
178178

179-
hass.async_add_job(
179+
hass.async_create_task(
180180
hass.config_entries.flow.async_init(
181181
DOMAIN, context={"source": SOURCE_IMPORT}, data=copy.deepcopy(CONFIG_YAML)
182182
)

custom_components/ble_monitor/binary_sensor.py

+17-11
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,15 @@ async def async_add_binary_sensor(key, device_model, firmware, auto_sensors, man
8888
if key not in sensors_by_key:
8989
sensors_by_key[key] = {}
9090
if measurement not in sensors_by_key[key]:
91-
entity_description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
92-
sensors[measurement] = globals()[entity_description.sensor_class](
93-
self.config, key, device_model, firmware, entity_description, manufacturer
94-
)
95-
self.add_entities([sensors[measurement]])
96-
sensors_by_key[key].update(sensors)
91+
try:
92+
entity_description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
93+
sensors[measurement] = globals()[entity_description.sensor_class](
94+
self.config, key, device_model, firmware, entity_description, manufacturer
95+
)
96+
self.add_entities([sensors[measurement]])
97+
sensors_by_key[key].update(sensors)
98+
except IndexError:
99+
_LOGGER.error("Error adding measurement %s", measurement)
97100
else:
98101
sensors = sensors_by_key[key]
99102
else:
@@ -102,11 +105,14 @@ async def async_add_binary_sensor(key, device_model, firmware, auto_sensors, man
102105
sensors = {}
103106
sensors_by_key[key] = {}
104107
for measurement in device_sensors:
105-
entity_description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
106-
sensors[measurement] = globals()[entity_description.sensor_class](
107-
self.config, key, device_model, firmware, entity_description, manufacturer
108-
)
109-
self.add_entities([sensors[measurement]])
108+
try:
109+
entity_description = [item for item in BINARY_SENSOR_TYPES if item.key is measurement][0]
110+
sensors[measurement] = globals()[entity_description.sensor_class](
111+
self.config, key, device_model, firmware, entity_description, manufacturer
112+
)
113+
self.add_entities([sensors[measurement]])
114+
except IndexError:
115+
_LOGGER.error("Error adding measurement %s", measurement)
110116
sensors_by_key[key] = sensors
111117
else:
112118
sensors = sensors_by_key[key]

custom_components/ble_monitor/ble_parser/__init__.py

+100-75
Large diffs are not rendered by default.

custom_components/ble_monitor/ble_parser/acconeer.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
}
2020

2121

22-
def parse_acconeer(self, data, source_mac, rssi):
22+
def parse_acconeer(self, data: bytes, mac: str):
2323
"""Acconeer parser"""
2424
msg_length = len(data)
2525
firmware = "Acconeer"
26-
acconeer_mac = source_mac
2726
device_id = data[4]
2827
xvalue = data[5:]
2928
result = {"firmware": firmware}
@@ -82,34 +81,27 @@ def parse_acconeer(self, data, source_mac, rssi):
8281
if device_type is None:
8382
if self.report_unknown == "Acconeer":
8483
_LOGGER.info(
85-
"BLE ADV from UNKNOWN Acconeer DEVICE: RSSI: %s, MAC: %s, ADV: %s",
86-
rssi,
87-
to_mac(source_mac),
84+
"BLE ADV from UNKNOWN Acconeer DEVICE: MAC: %s, ADV: %s",
85+
to_mac(mac),
8886
data.hex()
8987
)
9088
return None
9189

9290
# Check for duplicate messages
9391
packet_id = xvalue.hex()
9492
try:
95-
prev_packet = self.lpacket_ids[acconeer_mac]
93+
prev_packet = self.lpacket_ids[mac]
9694
except KeyError:
9795
# start with empty first packet
9896
prev_packet = None
9997
if prev_packet == packet_id:
10098
# only process new messages
10199
if self.filter_duplicates is True:
102100
return None
103-
self.lpacket_ids[acconeer_mac] = packet_id
104-
105-
# check for MAC presence in sensor whitelist, if needed
106-
if self.discovery is False and acconeer_mac not in self.sensor_whitelist:
107-
_LOGGER.debug("Discovery is disabled. MAC: %s is not whitelisted!", to_mac(acconeer_mac))
108-
return None
101+
self.lpacket_ids[mac] = packet_id
109102

110103
result.update({
111-
"rssi": rssi,
112-
"mac": to_unformatted_mac(acconeer_mac),
104+
"mac": to_unformatted_mac(mac),
113105
"type": device_type,
114106
"packet": packet_id,
115107
"firmware": firmware,

custom_components/ble_monitor/ble_parser/airmentor.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,9 @@ def parse_2s(msg_type, xvalue):
104104
return None
105105

106106

107-
def parse_airmentor(self, data: bytes, source_mac: str, rssi):
107+
def parse_airmentor(self, data: bytes, mac: str):
108108
"""Parser for Air Mentor"""
109109
data_length = len(data)
110-
airmentor_mac = source_mac
111110

112111
device_type = None
113112
result = None
@@ -127,21 +126,14 @@ def parse_airmentor(self, data: bytes, source_mac: str, rssi):
127126
if device_type is None or result is None:
128127
if self.report_unknown == "Air Mentor":
129128
_LOGGER.info(
130-
"BLE ADV from UNKNOWN Air Mentor DEVICE: RSSI: %s, MAC: %s, ADV: %s",
131-
rssi,
132-
to_mac(source_mac),
129+
"BLE ADV from UNKNOWN Air Mentor DEVICE: MAC: %s, ADV: %s",
130+
to_mac(mac),
133131
data.hex()
134132
)
135133
return None
136134

137-
# check for MAC presence in sensor whitelist, if needed
138-
if self.discovery is False and airmentor_mac not in self.sensor_whitelist:
139-
_LOGGER.debug("Discovery is disabled. MAC: %s is not whitelisted!", to_mac(airmentor_mac))
140-
return None
141-
142135
result.update({
143-
"rssi": rssi,
144-
"mac": to_unformatted_mac(airmentor_mac),
136+
"mac": to_unformatted_mac(mac),
145137
"type": device_type,
146138
"packet": "no packet id",
147139
"firmware": firmware,

custom_components/ble_monitor/ble_parser/almendo.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
_LOGGER = logging.getLogger(__name__)
88

99

10-
def parse_almendo(self, data, source_mac, rssi):
10+
def parse_almendo(self, data: bytes, mac: str):
1111
"""Almendo parser"""
1212
result = {
13-
"mac": to_unformatted_mac(source_mac),
14-
"rssi": rssi,
13+
"mac": to_unformatted_mac(mac),
1514
"data": False,
1615
"packet": "no packet id"
1716
}
@@ -48,25 +47,18 @@ def parse_almendo(self, data, source_mac, rssi):
4847
if result is None:
4948
if self.report_unknown == "Almendo":
5049
_LOGGER.info(
51-
"BLE ADV from UNKNOWN Almendo DEVICE: RSSI: %s, "
50+
"BLE ADV from UNKNOWN Almendo DEVICE: "
5251
"MAC: %s, ADV: %s",
53-
rssi,
54-
to_mac(source_mac),
52+
to_mac(mac),
5553
data.hex(),
5654
)
5755
return None
58-
# check for MAC presence in sensor whitelist, if needed
59-
if self.discovery is False and source_mac not in self.sensor_whitelist:
60-
_LOGGER.debug(
61-
"Discovery is disabled. MAC: %s is not whitelisted!",
62-
to_mac(source_mac),
63-
)
64-
return None
56+
6557
if version != 1:
6658
_LOGGER.info(
6759
"Protocol version %i on device %s not yet known "
6860
"by the Almendo parser",
6961
version,
70-
to_mac(source_mac),
62+
to_mac(mac),
7163
)
7264
return result

custom_components/ble_monitor/ble_parser/altbeacon.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,23 @@
55

66
from .const import (CONF_DATA, CONF_FIRMWARE, CONF_MAC, CONF_MAJOR,
77
CONF_MANUFACTURER, CONF_MEASURED_POWER, CONF_MINOR,
8-
CONF_PACKET, CONF_RSSI, CONF_TRACKER_ID, CONF_TYPE,
9-
CONF_UUID, DEFAULT_MANUFACTURER, MANUFACTURER_DICT)
8+
CONF_PACKET, CONF_TRACKER_ID, CONF_TYPE, CONF_UUID,
9+
DEFAULT_MANUFACTURER, MANUFACTURER_DICT)
1010
from .helpers import to_mac, to_unformatted_mac, to_uuid
1111

1212
_LOGGER = logging.getLogger(__name__)
1313

1414
DEVICE_TYPE: Final = "AltBeacon"
1515

1616

17-
def parse_altbeacon(self, data: str, comp_id: int, source_mac: str, rssi: float):
17+
def parse_altbeacon(self, data: str, comp_id: int, mac: str):
1818
"""parser for Alt Beacon"""
1919
if len(data) >= 27:
2020
uuid = data[6:22]
2121
(major, minor, power) = unpack(">HHb", data[22:27])
2222

2323
tracker_data = {
24-
CONF_RSSI: rssi,
25-
CONF_MAC: to_unformatted_mac(source_mac),
24+
CONF_MAC: to_unformatted_mac(mac),
2625
CONF_UUID: to_uuid(uuid).replace('-', ''),
2726
CONF_TRACKER_ID: uuid,
2827
CONF_MAJOR: major,
@@ -42,18 +41,11 @@ def parse_altbeacon(self, data: str, comp_id: int, source_mac: str, rssi: float)
4241
else:
4342
if self.report_unknown == DEVICE_TYPE:
4443
_LOGGER.info(
45-
"BLE ADV from UNKNOWN %s DEVICE: RSSI: %s, MAC: %s, ADV: %s",
44+
"BLE ADV from UNKNOWN %s DEVICE: MAC: %s, ADV: %s",
4645
DEVICE_TYPE,
47-
rssi,
48-
to_mac(source_mac),
46+
to_mac(mac),
4947
data.hex()
5048
)
5149
return None, None
5250

53-
# check for UUID presence in sensor whitelist, if needed
54-
if self.discovery is False and uuid and uuid not in self.sensor_whitelist:
55-
_LOGGER.debug("Discovery is disabled. UUID: %s is not whitelisted!", to_uuid(uuid))
56-
57-
return None, None
58-
5951
return sensor_data, tracker_data

custom_components/ble_monitor/ble_parser/amazfit.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
_LOGGER = logging.getLogger(__name__)
88

99

10-
def parse_amazfit(self, service_data, man_spec_data, source_mac, rssi):
10+
def parse_amazfit(self, service_data: str, man_spec_data: str, mac: str):
1111
"""parser for Amazfit scale and Miband 4 and 5"""
1212
if service_data:
1313
service_data_length = len(service_data)
@@ -65,23 +65,17 @@ def parse_amazfit(self, service_data, man_spec_data, source_mac, rssi):
6565
if self.report_unknown == "Amazfit":
6666
_LOGGER.info(
6767
"BLE ADV from UNKNOWN Amazfit Scale DEVICE: MAC: %s, service data: %s, manufacturer data: %s",
68-
to_mac(source_mac),
68+
to_mac(mac),
6969
service_data,
7070
man_spec_data
7171
)
7272
return None
7373

74-
# check for MAC presence in sensor whitelist, if needed
75-
if self.discovery is False and source_mac.lower() not in self.sensor_whitelist:
76-
_LOGGER.debug("Discovery is disabled. MAC: %s is not whitelisted!", to_mac(source_mac))
77-
return None
78-
7974
result.update({
8075
"type": device_type,
8176
"firmware": firmware,
82-
"mac": to_unformatted_mac(source_mac),
77+
"mac": to_unformatted_mac(mac),
8378
"packet": 'no packet id',
84-
"rssi": rssi,
8579
"data": True,
8680
})
8781
return result

custom_components/ble_monitor/ble_parser/atc.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
_LOGGER = logging.getLogger(__name__)
1010

1111

12-
def parse_atc(self, data, source_mac, rssi):
12+
def parse_atc(self, data: bytes, mac: str):
1313
"""Parse ATC BLE advertisements"""
1414
device_type = "ATC"
1515
msg_length = len(data)
@@ -45,7 +45,7 @@ def parse_atc(self, data, source_mac, rssi):
4545
adv_priority = 29
4646
elif msg_length == 15:
4747
# Parse BLE message in Custom format with encryption
48-
atc_mac = source_mac
48+
atc_mac = mac
4949
packet_id = data[4]
5050
firmware = "ATC (Custom encrypted)"
5151
decrypted_data = decrypt_atc(self, data, atc_mac)
@@ -70,7 +70,7 @@ def parse_atc(self, data, source_mac, rssi):
7070
adv_priority = 39
7171
elif msg_length == 12:
7272
# Parse BLE message in Atc1441 format with encryption
73-
atc_mac = source_mac
73+
atc_mac = mac
7474
packet_id = data[4]
7575
firmware = "ATC (Atc1441 encrypted)"
7676
decrypted_data = decrypt_atc(self, data, atc_mac)
@@ -97,17 +97,12 @@ def parse_atc(self, data, source_mac, rssi):
9797
else:
9898
if self.report_unknown == "ATC":
9999
_LOGGER.info(
100-
"BLE ADV from UNKNOWN ATC DEVICE: RSSI: %s, MAC: %s, AdStruct: %s",
101-
rssi,
102-
to_mac(source_mac),
100+
"BLE ADV from UNKNOWN ATC DEVICE: MAC: %s, AdStruct: %s",
101+
to_mac(mac),
103102
data.hex()
104103
)
105104
return None
106105

107-
# check for MAC presence in sensor whitelist, if needed
108-
if self.discovery is False and atc_mac not in self.sensor_whitelist:
109-
return None
110-
111106
try:
112107
prev_packet = self.lpacket_ids[atc_mac]
113108
except KeyError:
@@ -134,7 +129,6 @@ def parse_atc(self, data, source_mac, rssi):
134129
self.lpacket_ids[atc_mac] = packet_id
135130

136131
result.update({
137-
"rssi": rssi,
138132
"mac": to_unformatted_mac(atc_mac),
139133
"type": device_type,
140134
"packet": packet_id,

custom_components/ble_monitor/ble_parser/bluemaestro.py

+4-11
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
_LOGGER = logging.getLogger(__name__)
88

99

10-
def parse_bluemaestro(self, data, source_mac, rssi):
10+
def parse_bluemaestro(self, data: bytes, mac: str):
1111
"""Parse BlueMaestro advertisement."""
1212
msg_length = len(data)
1313
firmware = "BlueMaestro"
1414
device_id = data[4]
15-
bluemaestro_mac = source_mac
15+
bluemaestro_mac = mac
1616
msg = data[5:]
1717
if msg_length == 18 and device_id in [0x16, 0x17]:
1818
# BlueMaestro Tempo Disc THD
@@ -52,20 +52,13 @@ def parse_bluemaestro(self, data, source_mac, rssi):
5252
else:
5353
if self.report_unknown == "BlueMaestro":
5454
_LOGGER.info(
55-
"BLE ADV from UNKNOWN BlueMaestro DEVICE: RSSI: %s, MAC: %s, ADV: %s",
56-
rssi,
57-
to_mac(source_mac),
55+
"BLE ADV from UNKNOWN BlueMaestro DEVICE: MAC: %s, ADV: %s",
56+
to_mac(mac),
5857
data.hex()
5958
)
6059
return None
6160

62-
# check for MAC presence in whitelist, if needed
63-
if self.discovery is False and bluemaestro_mac not in self.sensor_whitelist:
64-
_LOGGER.debug("Discovery is disabled. MAC: %s is not whitelisted!", to_mac(bluemaestro_mac))
65-
return None
66-
6761
result.update({
68-
"rssi": rssi,
6962
"mac": to_unformatted_mac(bluemaestro_mac),
7063
"type": device_type,
7164
"packet": log_cnt,

0 commit comments

Comments
 (0)