From 303f8331dac612f848c875869284be0ca621692e Mon Sep 17 00:00:00 2001 From: Ernst Klamer Date: Mon, 18 Mar 2024 08:57:39 +0100 Subject: [PATCH] fix: remove mac workaround (#115) * fix: remove mac workaround --- src/bthome_ble/parser.py | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/bthome_ble/parser.py b/src/bthome_ble/parser.py index 9c00ed8..c239385 100644 --- a/src/bthome_ble/parser.py +++ b/src/bthome_ble/parser.py @@ -12,7 +12,6 @@ import logging import struct -import sys from datetime import datetime, timezone from enum import Enum from typing import Any @@ -145,11 +144,6 @@ def __init__(self, bindkey: bytes | None = None) -> None: # The packet_id is used to filter duplicate messages in BTHome V2. self.packet_id: float | None = 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 @@ -183,19 +177,6 @@ def set_bindkey(self, bindkey: bytes | None) -> None: def supported(self, data: BluetoothServiceInfoBleak) -> bool: if not super().supported(data): return False - - # Where a device uses encryption we need to know 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: BluetoothServiceInfoBleak) -> None: @@ -254,14 +235,7 @@ def _parse_bthome_v1( # Encrypted BTHome BLE format self.encryption_scheme = EncryptionScheme.BTHOME_BINDKEY self.set_device_sw_version("BTHome BLE v1 (encrypted)") - mac_readable = service_info.address - if len(mac_readable) != 17 and mac_readable[2] != ":": - # On macOS, we get a UUID, which is useless for BTHome sensors - self.mac_known = False - return False - else: - self.mac_known = True source_mac = bytes.fromhex(mac_readable.replace(":", "")) try: @@ -359,13 +333,6 @@ def _parse_bthome_v2( self.set_device_type(device_type) if self.encryption_scheme == EncryptionScheme.BTHOME_BINDKEY: - if len(mac_readable) != 17 and mac_readable[2] != ":": - # On macOS, we get a UUID, which is useless for BTHome sensors - # Unless the MAC address is specified in the payload - self.mac_known = False - return False - else: - self.mac_known = True bthome_mac = bytes.fromhex(mac_readable.replace(":", "")) # Decode encrypted payload try: