Skip to content

Commit

Permalink
fix: Catch pair as it fails if already paired
Browse files Browse the repository at this point in the history
  • Loading branch information
sopelj committed Jan 15, 2022
1 parent b6b55c3 commit 4525bd6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions custom_components/ember_mug/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Add Config Flow for Ember Mug."""
from __future__ import annotations

import contextlib
import re
from typing import Any, Optional

Expand Down Expand Up @@ -37,12 +38,14 @@ async def async_step_user(self, user_input: Optional[dict[str, Any]] = None):
name, mac_address = match.groups()[:2]
try:
async with BleakClient(mac_address) as client:
connected = True
if not client.is_connected:
connected = await client.connect()
_LOGGER.info(f"Connected: {connected}")
paired = await client.pair()
_LOGGER.info(f"Paired: {paired}")
if not paired:
with contextlib.suppress(BleakError):
paired = await client.pair()
_LOGGER.info(f"Paired: {paired}")
if not connected:
errors["base"] = "not_connected"
except BleakError as e:
_LOGGER.error(f"Bleak Error whilst connecting: {e}")
Expand Down

0 comments on commit 4525bd6

Please sign in to comment.