diff --git a/src/xiaomi_ble/parser.py b/src/xiaomi_ble/parser.py index 055d60c..8a43370 100644 --- a/src/xiaomi_ble/parser.py +++ b/src/xiaomi_ble/parser.py @@ -9,7 +9,6 @@ import logging import math import struct -import sys from typing import Any from bleak import BleakClient @@ -1481,11 +1480,6 @@ def __init__(self, bindkey: bytes | None = None) -> None: # frame. self.encryption_scheme = EncryptionScheme.NONE - # If true, then we know the actual MAC of the device. - # On macOS, we don't unless the device includes it in the advertisement - # (CoreBluetooth uses UUID's generated by CoreBluetooth instead of the MAC) - self.mac_known = sys.platform != "darwin" - # If true then we have used the provided encryption key to decrypt at least # one payload. # If false then we have either not seen an encrypted payload, the key is wrong @@ -1522,19 +1516,6 @@ def set_bindkey(self, bindkey: bytes | None) -> None: def supported(self, data: BluetoothServiceInfo) -> bool: if not super().supported(data): return False - - # Where a device uses encryption we need to known its actual MAC address. - # As the encryption uses it as part of the nonce. - # On macOS we instead only know its CoreBluetooth UUID. - # It seems its impossible to automatically get that in the general case. - # So devices do duplicate the MAC in the advertisement, we use that - # when we can on macOS. - # We may want to ask the user for the MAC address during config flow - # For now, just hide these devices for macOS users. - if self.encryption_scheme != EncryptionScheme.NONE: - if not self.mac_known: - return False - return True def _start_update(self, service_info: BluetoothServiceInfo) -> None: @@ -1594,10 +1575,6 @@ def _parse_xiaomi( return False mac_readable = service_info.address - if len(mac_readable) != 17 and mac_readable[2] != ":": - # On macOS we get a UUID, which is useless for MiBeacons - mac_readable = "00:00:00:00:00:00" - source_mac = bytes.fromhex(mac_readable.replace(":", "")) # extract frame control bits @@ -1637,14 +1614,13 @@ def _parse_xiaomi( return False xiaomi_mac_reversed = data[5:11] xiaomi_mac = xiaomi_mac_reversed[::-1] - if sys.platform != "darwin" and xiaomi_mac != source_mac: + if xiaomi_mac != source_mac: _LOGGER.debug( "MAC address doesn't match data frame. Expected: %s, Got: %s)", to_mac(xiaomi_mac), to_mac(source_mac), ) return False - self.mac_known = True else: xiaomi_mac = source_mac