Skip to content

Commit

Permalink
feat: Allow setup of devices with either service uuids or name matching
Browse files Browse the repository at this point in the history
  • Loading branch information
sopelj committed Feb 12, 2024
1 parent 048813b commit 31d64ee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/ember_mug/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import voluptuous as vol
from bleak import BleakClient, BleakError
from ember_mug.consts import DEVICE_SERVICE_UUIDS
from homeassistant import config_entries
from homeassistant.components.bluetooth import async_discovered_service_info
from homeassistant.const import (
Expand Down Expand Up @@ -80,10 +81,17 @@ async def async_step_user(
for service_info in async_discovered_service_info(self.hass):
address = service_info.address
unique_id = address.replace(":", "").lower()
_LOGGER.debug("Found device %s with services: %s", service_info.name, service_info.service_uuids)
if unique_id in current_addresses:
_LOGGER.debug("Skipping device %s which is already setup", service_info.address)
continue
if not service_info.name or not service_info.name.startswith("Ember"):
if not set(service_info.service_uuids).intersection(DEVICE_SERVICE_UUIDS) and (
not service_info.name or not service_info.name.startswith("Ember")
):
_LOGGER.debug(
"Skipping unrelated device %s with services: %s",
service_info.name,
service_info.service_uuids,
)
continue
try:
async with BleakClient(service_info.device) as client:
Expand Down

0 comments on commit 31d64ee

Please sign in to comment.