Skip to content

Commit

Permalink
Add notificationg for companion users to set Minor=40004
Browse files Browse the repository at this point in the history
  • Loading branch information
chatziko committed Nov 23, 2023
1 parent d013f0d commit 6e43007
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion homeassistant/components/ibeacon/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
iBeaconParser,
)

from homeassistant.components import bluetooth
from homeassistant.components import bluetooth, persistent_notification
from homeassistant.components.bluetooth.match import BluetoothCallbackMatcher
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
Expand Down Expand Up @@ -116,6 +116,7 @@ def __init__(
self._entry = entry
self._dev_reg = registry
self._ibeacon_parser = iBeaconParser()
self._persistent_notification_sent = False

# iBeacon devices that do not follow the spec
# and broadcast custom data in the major and minor fields
Expand Down Expand Up @@ -310,6 +311,26 @@ def _async_update_ibeacon_with_unique_address(
== service_info.device.address
)
):
# Past versions of the Companion Apps's BLE transmitter used major=100, minor=1 by default, so if we
# see an ignored beacon with these values it's likely the Companion App. We print a warning and create
# a persistent notification to inform the user how to solve the problem.
#
if ibeacon_advertisement.major == 100 and ibeacon_advertisement.minor == 1:
_LOGGER.warning(

Check warning on line 319 in homeassistant/components/ibeacon/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/ibeacon/coordinator.py#L319

Added line #L319 was not covered by tests
"You are likely using a Companion App BLE transmitter from an Android device that does not broadcast its name. The beacon %s will be ignored. You can fix this issue by setting Minor=40004 in the companion app settings",
unique_id,
)

# At most one persistent notification to avoid spamming
if not self._persistent_notification_sent:
self._persistent_notification_sent = True

Check warning on line 326 in homeassistant/components/ibeacon/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/ibeacon/coordinator.py#L325-L326

Added lines #L325 - L326 were not covered by tests

persistent_notification.async_create(

Check warning on line 328 in homeassistant/components/ibeacon/coordinator.py

View check run for this annotation

Codecov / codecov/patch

homeassistant/components/ibeacon/coordinator.py#L328

Added line #L328 was not covered by tests
self.hass,
title="BLE transmitter iBeacon ignored",
message="You are likely using a Companion App BLE transmitter from an Android device that does not broadcast its name. Such iBeacons will be ignored.\n\nYou can fix this issue by setting Minor=40004 in the settings of the BLE Transmitter.",
)

_LOGGER.debug("ignoring new beacon %s due to empty name", unique_id)
return

Expand Down

0 comments on commit 6e43007

Please sign in to comment.