{
  "id": "task_libraries:bluetooth/python",
  "path": "/exapedia/python-bluetooth-libraries",
  "template": {
    "id": "task_libraries",
    "version": 4
  },
  "title": "Python Bluetooth libraries",
  "answer": [
    {
      "t": "text",
      "text": "Python Bluetooth libraries scan for nearby devices, connect to them, and read or write their data. A Bluetooth Low Energy client talks to a device through GATT services and characteristics. These libraries let IoT tools, home automation systems, and test rigs control sensors and wearables."
    }
  ],
  "breadcrumb": [
    {
      "label": "Tools"
    },
    {
      "label": "Python Bluetooth libraries"
    }
  ],
  "sections": [
    {
      "id": "libraries_popularity",
      "anchor": "popularity",
      "heading": "Popularity",
      "blocks": [
        {
          "b": "table",
          "columns": [
            "Library",
            "Monthly downloads",
            "Stars",
            "Last release",
            "License"
          ],
          "rows": [
            [
              [
                {
                  "t": "link",
                  "href": "#bleak",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F129"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F130"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F136"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F133"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F131"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#habluetooth",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F144"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F145"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F153"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F148"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F146"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bleak-retry-connector",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F161"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F162"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F170"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F165"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F163"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bumble",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F178"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F179"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F187"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F182"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F180"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#simplepyble",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F195"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F196"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F204"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F199"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F197"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#aioblescan",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F212"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F213"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F221"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F216"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F214"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bleak-esphome",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F229"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F230"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F238"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F233"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F231"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bless",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F246"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F247"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F253"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F250"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F248"
                }
              ]
            ]
          ],
          "variant": "pop",
          "caption": [
            {
              "t": "text",
              "text": "Downloads: "
            },
            {
              "t": "text",
              "text": "PyPI"
            },
            {
              "t": "text",
              "text": ", last thirty days. Stars and releases: GitHub. Amber: no release in over a year."
            }
          ]
        }
      ],
      "note": [
        {
          "t": "link",
          "href": "#bleak",
          "label": [
            {
              "t": "fact",
              "fact": "F1"
            }
          ]
        },
        {
          "t": "text",
          "text": " has the most monthly downloads in this comparison, at "
        },
        {
          "t": "fact",
          "fact": "F2"
        },
        {
          "t": "text",
          "text": "."
        }
      ]
    },
    {
      "id": "libraries_capabilities",
      "anchor": "capabilities",
      "heading": "Capabilities",
      "blocks": [
        {
          "b": "table",
          "columns": [
            "Library",
            "Local GATT server",
            "Classic RFCOMM stack"
          ],
          "rows": [
            [
              [
                {
                  "t": "link",
                  "href": "#bleak",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F129"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F137"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F138"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#habluetooth",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F144"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F154"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F155"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bleak-retry-connector",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F161"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F171"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F172"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bumble",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F178"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F188"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F189"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#simplepyble",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F195"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F205"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F206"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#aioblescan",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F212"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F222"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F223"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bleak-esphome",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F229"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F239"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F240"
                }
              ]
            ],
            [
              [
                {
                  "t": "link",
                  "href": "#bless",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F246"
                    }
                  ]
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F254"
                }
              ],
              [
                {
                  "t": "fact",
                  "fact": "F255"
                }
              ]
            ]
          ],
          "variant": "cap"
        }
      ]
    },
    {
      "id": "libraries_entries",
      "anchor": "libraries",
      "heading": "Libraries",
      "blocks": [
        {
          "b": "entry",
          "anchor": "bleak",
          "name": [
            {
              "t": "fact",
              "fact": "F129"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/hbldh/bleak"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/bleak"
            },
            {
              "label": "Docs",
              "href": "https://bleak.readthedocs.io/en/latest/api/client.html"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F11"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F130"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F136"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F132"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F131"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://bleak.readthedocs.io/en/latest/api/client.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F129"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F12"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F13"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F14"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F15"
                }
              ]
            }
          ],
          "cons": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F16"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F17"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F18"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F19"
                }
              ]
            }
          ],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F142"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F143"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/home-assistant/core",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F142"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "async def _async_see_update_ble_battery(\n    mac: str,\n    now: datetime,\n    service_info: bluetooth.BluetoothServiceInfoBleak,\n) -> None:\n    \"\"\"Lookup Bluetooth LE devices and update status.\"\"\"\n    battery = None\n    # We need one we can connect to since the tracker will\n    # accept devices from non-connectable sources\n    if service_info.connectable:\n        device = service_info.device\n    elif connectable_device := bluetooth.async_ble_device_from_address(\n        hass, service_info.device.address, True\n    ):\n        device = connectable_device\n    else:\n        # The device can be seen by a passive tracker but we\n        # don't have a route to make a connection\n        return\n    try:\n        async with BleakClient(device) as client:\n            bat_char = await client.read_gatt_char(BATTERY_CHARACTERISTIC_UUID)\n            battery = ord(bat_char)\n    except TimeoutError:\n        _LOGGER.debug(\n            \"Timeout when trying to get battery status for %s\", service_info.name\n        )\n    # Bleak currently has a few places where checking dbus attributes\n    # can raise when there is another error. We need to trap AttributeError\n    # until bleak releases v0.15+ which resolves these.\n    except (AttributeError, BleakError) as err:\n        _LOGGER.debug(\"Could not read battery status: %s\", err)\n        # If the device does not offer battery information,\n        # there is no point in asking again later on.\n        # Remove the device from the battery-tracked\n        # devices, so that their battery is not wasted\n        # trying to get an unavailable information.\n        del devs_track_battery[mac]\n    if battery:\n        await async_see_device(mac, service_info.name, battery=battery)",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/home-assistant/core/blob/eca50a4e0d47a97f44061418ffcbfb918d4d2a61/homeassistant/components/bluetooth_le_tracker/device_tracker.py",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F141"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=Real%20projects%20using%20bleak%20for%20Bluetooth%20device%20communication&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F129"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import asyncio\nfrom bleak import BleakScanner\n\nasync def main():\n    print(await BleakScanner.discover())\n\nasyncio.run(main())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://bleak.readthedocs.io/en/latest/api/client.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "usage.html"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F134"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "habluetooth",
          "name": [
            {
              "t": "fact",
              "fact": "F144"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/Bluetooth-Devices/habluetooth"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/habluetooth"
            },
            {
              "label": "Docs",
              "href": "https://habluetooth.readthedocs.io/en/latest/"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F151"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F145"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F153"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F147"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F146"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://habluetooth.readthedocs.io/en/latest/",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F144"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F159"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F160"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/home-assistant/core",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F159"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:\n    \"\"\"Set up a config entry for a bluetooth scanner.\"\"\"\n    if source_entry_id := entry.data.get(CONF_SOURCE_CONFIG_ENTRY_ID):\n        if not (source_entry := hass.config_entries.async_get_entry(source_entry_id)):\n            # Cleanup the orphaned entry using a call_soon to ensure\n            # we can return before the entry is removed\n            hass.loop.call_soon(\n                hass_callback(\n                    lambda: hass.async_create_task(\n                        hass.config_entries.async_remove(entry.entry_id),\n                        \"remove orphaned bluetooth entry {entry.entry_id}\",\n                    )\n                )\n            )\n            return\n        address = entry.unique_id\n        assert address is not None\n        source_domain = entry.data[CONF_SOURCE_DOMAIN]\n        if mac_manufacturer := await get_manufacturer_from_mac(address):\n            manufacturer = f\"{mac_manufacturer} ({source_domain})\"\n        else:\n            manufacturer = source_domain\n        details = AdapterDetails(\n            address=address,\n            product=entry.data.get(CONF_SOURCE_MODEL),\n            manufacturer=manufacturer,\n        )\n        await async_update_device(\n            hass,\n            entry,\n            source_entry.title,\n            details,\n            entry.data.get(CONF_SOURCE_DEVICE_ID),\n        )\n        return\n    manager = _get_manager(hass)\n    address = entry.unique_id\n    assert address is not None\n    adapter = await manager.async_get_adapter_from_address_or_recover(address)\n    if adapter is None:\n        raise ConfigEntryNotReady(\n            f\"Bluetooth adapter {adapter} with address {address} not found\"\n        )\n    adapters = await manager.async_get_bluetooth_adapters()\n    details = adapters[adapter]\n    mode = resolve_scanning_mode(entry.options)\n    # AUTO needs passive scanning support to flip on demand; without it\n    # the scanner would start passive on hardware that can't do passive.\n    if mode is BluetoothScanningMode.AUTO and not details.get(ADAPTER_PASSIVE_SCAN):\n        mode = BluetoothScanningMode.ACTIVE\n    scanner = HaScanner(mode, adapter, address)\n    entry.async_on_unload(scanner.async_setup())\n    if entry.title == address:\n        hass.config_entries.async_update_entry(\n            entry, title=adapter_title(adapter, details)\n        )\n    slots: int = details.get(ADAPTER_CONNECTION_SLOTS) or DEFAULT_CONNECTION_SLOTS\n    # Register the scanner before starting so\n    # any raw advertisement data can be processed\n    entry.async_on_unload(async_register_scanner(hass, scanner, connection_slots=slots))\n    await async_update_device(hass, entry, adapter, details)\n    try:\n        await scanner.async_start()\n    except (RuntimeError, ScannerStartError) as err:\n        raise ConfigEntryNotReady(\n            f\"{adapter_human_name(adapter, address)}: {err}\"\n        ) from err\n    entry.async_on_unload(entry.add_update_listener(async_update_listener))\n    entry.async_on_unload(scanner.async_stop)",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/home-assistant/core/blob/3df93331719fcb206ab24c165cadf1e796d52c02/homeassistant/components/bluetooth/__init__.py",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F158"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=habluetooth%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F144"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import asyncio\nfrom habluetooth import BluetoothManager\n\nasync def main():\n    manager = BluetoothManager()\n    await manager.async_setup()\n    try:\n        print(await manager.async_get_bluetooth_adapters())\n    finally:\n        manager.async_stop()\n\nasyncio.run(main())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/Bluetooth-Devices/habluetooth/blob/1388841581abf6264cb202c6628734d96bfa1ffc/src/habluetooth/manager.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "manager.py"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F149"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "bleak-retry-connector",
          "name": [
            {
              "t": "fact",
              "fact": "F161"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/Bluetooth-Devices/bleak-retry-connector"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/bleak-retry-connector"
            },
            {
              "label": "Docs",
              "href": "https://bleak-retry-connector.readthedocs.io/en/latest/usage.html"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F168"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F162"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F170"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F164"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F163"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://bleak-retry-connector.readthedocs.io/en/latest/usage.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F161"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F176"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F177"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/sblibs/pySwitchbot",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F176"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "async def _ensure_connected(self):\n    \"\"\"Ensure connection to device is established.\"\"\"\n    if self._connect_lock.locked():\n        _LOGGER.debug(\n            \"%s: Connection already in progress, waiting for it to complete; RSSI: %s\",\n            self.name,\n            self.rssi,\n        )\n    if self._client and self._client.is_connected:\n        _LOGGER.debug(\n            \"%s: Already connected before obtaining lock, resetting timer; RSSI: %s\",\n            self.name,\n            self.rssi,\n        )\n        self._reset_disconnect_timer()\n        return\n    async with self._connect_lock:\n        # Check again while holding the lock\n        if self._client and self._client.is_connected:\n            _LOGGER.debug(\n                \"%s: Already connected after obtaining lock, resetting timer; RSSI: %s\",\n                self.name,\n                self.rssi,\n            )\n            self._reset_disconnect_timer()\n            return\n        _LOGGER.debug(\"%s: Connecting; RSSI: %s\", self.name, self.rssi)\n        client: BleakClientWithServiceCache = await establish_connection(\n            BleakClientWithServiceCache,\n            self._device,\n            self.name,\n            self._disconnected,\n            use_services_cache=True,\n            ble_device_callback=lambda: self._device,\n        )\n        _LOGGER.debug(\"%s: Connected; RSSI: %s\", self.name, self.rssi)\n        self._client = client\n\n        try:\n            self._resolve_characteristics(client.services)\n        except CharacteristicMissingError as ex:\n            _LOGGER.debug(\n                \"%s: characteristic missing, clearing cache: %s; RSSI: %s\",\n                self.name,\n                ex,\n                self.rssi,\n                exc_info=True,\n            )\n            await client.clear_cache()\n            self._cancel_disconnect_timer()\n            await self._execute_disconnect_with_lock()\n            raise\n\n        _LOGGER.debug(\n            \"%s: Starting notify and disconnect timer; RSSI: %s\",\n            self.name,\n            self.rssi,\n        )\n        self._reset_disconnect_timer()\n        await self._start_notify()",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/Danielhiversen/pySwitchbot/blob/ff409b2ee70672d2f50aae51a1250a6b9a942e45/switchbot/devices/device.py",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F175"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=bleak-retry-connector%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F161"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import asyncio, os\nfrom bleak import BleakScanner\nfrom bleak_retry_connector import establish_connection, BleakClientWithServiceCache\n\nasync def main():\n    device = await BleakScanner.find_device_by_address(os.environ[\"BLE_ADDRESS\"])\n    if device is None:\n        raise RuntimeError(\"Device not found\")\n    client = await establish_connection(BleakClientWithServiceCache, device, device.name or device.address)\n    try:\n        print(client.services)\n    finally:\n        await client.disconnect()\n\nasyncio.run(main())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/Bluetooth-Devices/bleak-retry-connector/blob/0bdeaf11d91aa954ee0973ba06c9aba52ddb9971/src/bleak_retry_connector/__init__.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "usage.html"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F166"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "bumble",
          "name": [
            {
              "t": "fact",
              "fact": "F178"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/google/bumble"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/bumble"
            },
            {
              "label": "Docs",
              "href": "https://google.github.io/bumble/"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F185"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F179"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F187"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F181"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F180"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://google.github.io/bumble/",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F178"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F193"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F194"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/raspberrypi/pico-examples",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F193"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def make_pairing_config(security: int) -> PairingConfig:\n    \"\"\"Return a Bumble PairingConfig matching the given security setting.\"\"\"\n    # All modes use Secure Connections (sc=True) and bonding, matching the\n    # sm_set_secure_connections_only_mode(true) call in the Pico client.\n    common = dict(sc=True, bonding=True)\n    if security == 0:\n        # Just Works: no I/O capability, no MITM\n        return PairingConfig(mitm=False, delegate=PairingDelegate(\n            io_capability=PairingDelegate.IoCapability.NO_OUTPUT_NO_INPUT,\n        ), **common)\n    elif security == 1:\n        # Numeric Comparison: server displays, client confirms yes/no\n        return PairingConfig(mitm=True, delegate=PairingDelegate(\n            io_capability=PairingDelegate.IoCapability.DISPLAY_OUTPUT_AND_YES_NO_INPUT,\n        ), **common)\n    elif security == 2:\n        # Keyboard + Display: matches IO_CAPABILITY_KEYBOARD_DISPLAY on the Pico.\n        # Pairing method depends on the other side's capabilities.\n        return PairingConfig(mitm=True, delegate=KeyboardDelegate(\n            io_capability=PairingDelegate.IoCapability.DISPLAY_OUTPUT_AND_KEYBOARD_INPUT,\n        ), **common)\n    else:\n        # security == 3: Display Only - matches IO_CAPABILITY_DISPLAY_ONLY on the Pico.\n        # Requires the Pico client to be built with SECURITY_SETTING=2 (KEYBOARD_DISPLAY)\n        # so it can enter the passkey we display here.\n        return PairingConfig(mitm=True, delegate=DisplayDelegate(), **common)\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/raspberrypi/pico-examples/blob/0d62f75bafc2c8120d3276c3343d1a9195e909e9/bluetooth/ble_secure_temp_sensor/ble_temp_server.py#L118-L143",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F192"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=bumble%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F178"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import asyncio, os\nfrom bumble.device import Device\nfrom bumble.hci import Address\nfrom bumble.transport import open_transport\n\nasync def main():\n    async with await open_transport(os.environ[\"BUMBLE_TRANSPORT\"]) as transport:\n        device = Device.with_hci(\"Bumble\", Address(\"F0:F1:F2:F3:F4:F5\"), transport.source, transport.sink)\n        await device.power_on()\n        await device.start_scanning()\n        await asyncio.sleep(5)\n        await device.stop_scanning()\n\nasyncio.run(main())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/google/bumble/blob/a679beb4f36681c6f1b6d72b7e825c6f57f9ef83/bumble/device.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "device.py"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F183"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "simplepyble",
          "name": [
            {
              "t": "fact",
              "fact": "F195"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/simpleble/simpleble"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/simplepyble"
            },
            {
              "label": "Docs",
              "href": "https://simpleble.readthedocs.io/en/latest/simplepyble.html"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F202"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F196"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F204"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F198"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F197"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://simpleble.readthedocs.io/en/latest/simplepyble.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F195"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F210"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F211"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/javl/InstaxBLE",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F210"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def connect(self, timeout=0):\n    \"\"\" Connect to the printer. Stops trying after <timeout> seconds. \"\"\"\n    if self.dummyPrinter:\n        return\n\n    self.peripheral = self.find_device(timeout=timeout)\n    if self.peripheral:\n        try:\n            self.log(f\"Connecting to {self.peripheral.identifier()} [{self.peripheral.address()}]\")\n            self.peripheral.connect()\n        except Exception as e:\n            if not self.quiet:\n                self.log(f'error on connecting: {e}')\n\n        if self.peripheral.is_connected():\n            # check if we're using a version of simplepyble that supports reading mtu\n            self.log(f\"Connected\")\n\n            # self.log('Attaching notification_handler')\n            try:\n                self.peripheral.notify(self.serviceUUID, self.notifyCharUUID, self.notification_handler)\n            except Exception as e:\n                if not self.quiet:\n                    self.log(f'Error on attaching notification_handler: {e}')\n                    return\n\n            self.get_printer_info()\n            sleep(1)\n            self.display_current_status()\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/javl/InstaxBLE/blob/804dca8cfaba5db48bc5f961aab106006e600303/InstaxBLE.py#L194-L222",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F209"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=simplepyble%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F195"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import simplepyble\n\nadapters = simplepyble.Adapter.get_adapters()\nif not adapters:\n    raise RuntimeError(\"No Bluetooth adapter found\")\nadapter = adapters[0]\nadapter.scan_for(1000)\nprint(adapter.scan_get_results())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/simpleble/simpleble/blob/53625c90ff922256baf1a1081b9dcee263390298/simplepyble/src/simplepyble/aio.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "wrap_adapter.cpp"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F200"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "aioblescan",
          "name": [
            {
              "t": "fact",
              "fact": "F212"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/frawau/aioblescan"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/aioblescan"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F219"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F213"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F221"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F215"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F214"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://github.com/frawau/aioblescan",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F212"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F227"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F228"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/custom-components/ble_monitor",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F227"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "def run(self):\n    \"\"\"Run HCIdump thread.\"\"\"\n    while True:\n        _LOGGER.debug(\"HCIdump thread: Run\")\n        mysocket = {}\n        fac = {}\n        conn = {}\n        btctrl = {}\n        interface_is_ok = {}\n        interfaces_to_reset = []\n        initialized_evt = {}\n        retry_handle = None\n        if self._event_loop is None:\n            self._event_loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(self._event_loop)\n        if \"disable\" not in self.config[CONF_BT_INTERFACE]:\n            for hci in self._interfaces:\n                interface_is_ok[hci] = False\n                try:\n                    mysocket[hci] = aiobs.create_bt_socket(hci)\n                except OSError as error:\n                    _LOGGER.error(\"HCIdump thread: OS error (hci%i): %s\", hci, error)\n                else:\n                    fac[hci] = getattr(\n                        self._event_loop, \"_create_connection_transport\"\n                    )(mysocket[hci], aiobs.BLEScanRequester, None, None)\n                    conn[hci], btctrl[hci] = self._event_loop.run_until_complete(\n                        fac[hci]\n                    )\n                    # Wait up to five seconds for aioblescan BLEScanRequester to initialize\n                    initialized_evt[hci] = getattr(btctrl[hci], \"_initialized\")\n                    _LOGGER.debug(\n                        \"HCIdump thread: BLEScanRequester._initialized is %s for hci%i, \"\n                        \" waiting for connection...\",\n                        initialized_evt[hci].is_set(),\n                        hci,\n                    )\n                    try:\n                        self._event_loop.run_until_complete(asyncio.wait_for(initialized_evt[hci].wait(), 5))\n                    except asyncio.TimeoutError:\n                        _LOGGER.warn(\n                            \"HCIdump thread: Something wrong - interface hci%i not ready,\"\n                            \" and will be skipped for current scan period.\",\n                            hci,\n                        )\n                        conn[hci].close()\n                        fac[hci].close()\n                        mysocket[hci].close()\n                    else:\n                        btctrl[hci].process = partial(\n                            self.process_hci_events, hci=hci\n                        )\n                        _LOGGER.debug(\"HCIdump thread: connected to hci%i\", hci)\n                        try:\n                            self._event_loop.run_until_complete(\n                                btctrl[hci].send_scan_request(self._active)\n                            )\n                        except RuntimeError as error:\n                            _LOGGER.error(\n                                \"HCIdump thread: Runtime error while sending scan request on hci%i: %s.\",\n                                hci,\n                                error,\n                            )\n                            conn[hci].close()\n                            fac[hci].close()\n                            mysocket[hci].close()\n                        else:\n                            interface_is_ok[hci] = True\n                            self._record_hci_activity(hci)\n                            _LOGGER.debug(\n                                \"HCIdump thread: BLEScanRequester._initialized is %s for hci%i, \"\n                                \" connection established, send_scan_request succeeded.\",\n                                initialized_evt[hci].is_set(),\n                                hci,\n                            )\n                if interface_is_ok[hci] is False:\n                    self._last_hci_activity.pop(hci, None)\n                if (interface_is_ok[hci] is False) and (self.config[CONF_BT_AUTO_RESTART] is True):\n                    interfaces_to_reset.append(hci)\n            if interfaces_to_reset:\n                ts_now = time.monotonic()\n                if ts_now - self.last_bt_reset > 60:\n                    for iface in interfaces_to_reset:\n                        _LOGGER.error(\n                            \"HCIdump thread: Trying to power cycle Bluetooth adapter hci%i %s,\"\n                            \" will try to use it next scan period.\",\n                            iface,\n                            BT_INTERFACES[iface],\n                        )\n                        reset_bluetooth(iface)\n                    self.last_bt_reset = ts_now\n            if not all(interface_is_ok.values()):\n                retry_handle = self._schedule_scan_retry()\n        self._schedule_watchdog()\n        _LOGGER.debug(\"HCIdump thread: start main event_loop\")\n        try:\n            self._event_loop.run_forever()\n        finally:\n            _LOGGER.debug(\"HCIdump thread: main event_loop stopped, finishing.\")\n            if self._watchdog_handle is not None:\n                self._watchdog_handle.cancel()\n                self._watchdog_handle = None\n            if retry_handle is not None:\n                retry_handle.cancel()\n            if \"disable\" not in self.config[CONF_BT_INTERFACE]:\n                for hci in self._interfaces:\n                    if interface_is_ok[hci] is True:\n                        try:\n                            self._event_loop.run_until_complete(\n                                btctrl[hci].stop_scan_request()\n                            )\n                        except RuntimeError as error:\n                            _LOGGER.error(\n                                \"HCIdump thread: Runtime error while stop scan request on hci%i: %s.\",\n                                hci,\n                                error,\n                            )\n                        except KeyError:\n                            _LOGGER.debug(\n                                \"HCIdump thread: Key error while stop scan request on hci%i\",\n                                hci,\n                            )\n                    try:\n                        conn[hci].close()\n                        fac[hci].close()\n                        mysocket[hci].close()\n                    except KeyError:\n                        _LOGGER.debug(\n                            \"HCIdump thread: Key error while closing connection on hci%i\",\n                            hci,\n                        )\n                    self._last_hci_activity.pop(hci, None)\n            self._event_loop.run_until_complete(asyncio.sleep(0))\n        if self._joining is True:\n            break\n        _LOGGER.debug(\"HCIdump thread: Scanning will be restarted\")\n        _LOGGER.debug(\n            \"HCI events processed for previous scan: %s\", self.evt_cnt\n        )\n        self.evt_cnt = {}\n    self._event_loop.close()\n    _LOGGER.debug(\"HCIdump thread: Run finished\")",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/custom-components/ble_monitor/blob/a89251f8b47f25ba48176642f4fc63e4951d78d2/custom_components/ble_monitor/__init__.py",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F226"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=aioblescan%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F212"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "python3.11 -m aioblescan -D 0\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/frawau/aioblescan/blob/233a402248d176f15e07335d4a0d919d4391fdb6/aioblescan/aioblescan.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "README.md"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F217"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "bleak-esphome",
          "name": [
            {
              "t": "fact",
              "fact": "F229"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/Bluetooth-Devices/bleak-esphome"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/bleak-esphome"
            },
            {
              "label": "Docs",
              "href": "https://bleak-esphome.readthedocs.io/en/latest/usage.html"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F236"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F230"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F238"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F232"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F231"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://bleak-esphome.readthedocs.io/en/latest/usage.html",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F229"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [],
          "cons": [],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F244"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F245"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/home-assistant/core",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F244"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "@hass_callback\ndef async_connect_scanner(\n    hass: HomeAssistant,\n    entry: ESPHomeConfigEntry,\n    entry_data: RuntimeEntryData,\n    cli: APIClient,\n    device_info: DeviceInfo,\n    device_id: str,\n) -> CALLBACK_TYPE:\n    \"\"\"Connect scanner.\"\"\"\n    client_data = connect_scanner(cli, device_info, entry_data.available)\n    entry_data.bluetooth_device = client_data.bluetooth_device\n    client_data.disconnect_callbacks = entry_data.disconnect_callbacks\n    scanner = client_data.scanner\n    if TYPE_CHECKING:\n        assert scanner is not None\n    api_version = cli.api_version or APIVersion()\n    feature_flags = device_info.bluetooth_proxy_feature_flags_compat(api_version)\n    state_and_mode = bool(feature_flags & BluetoothProxyFeature.FEATURE_STATE_AND_MODE)\n    # Pin mode before async_register_scanner so habluetooth spawns the AUTO worker.\n    deferred_migration: CALLBACK_TYPE | None = None\n    if state_and_mode:\n        deferred_migration = _async_apply_scanning_mode(hass, entry, scanner, cli)\n    callbacks: list[CALLBACK_TYPE] = [\n        async_register_scanner(\n            hass,\n            scanner,\n            source_domain=DOMAIN,\n            source_model=device_info.model,\n            source_config_entry_id=entry_data.entry_id,\n            source_device_id=device_id,\n        ),\n        scanner.async_setup(),\n    ]\n    if deferred_migration is not None:\n        callbacks.append(deferred_migration)\n    return partial(_async_unload, callbacks)",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/home-assistant/core/blob/3df93331719fcb206ab24c165cadf1e796d52c02/homeassistant/components/esphome/bluetooth.py",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F243"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=bleak-esphome%20GitHub%20projects",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F229"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import asyncio, os\nfrom habluetooth import BluetoothManager\nfrom bleak import BleakScanner\nfrom bleak_esphome import APIConnectionManager\n\nasync def main():\n    manager = BluetoothManager()\n    await manager.async_setup()\n    connection = APIConnectionManager({\"address\": os.environ[\"ESPHOME_HOST\"], \"noise_psk\": os.getenv(\"ESPHOME_NOISE_PSK\")})\n    try:\n        await connection.start()\n        print(await BleakScanner.discover())\n    finally:\n        await connection.stop()\n        manager.async_stop()\n\nasyncio.run(main())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/Bluetooth-Devices/bleak-esphome/blob/d9423774aac79ed969730205bfb42da7f70fbd59/src/bleak_esphome/connect.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "usage.html"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F234"
            }
          ]
        },
        {
          "b": "entry",
          "anchor": "bless",
          "name": [
            {
              "t": "fact",
              "fact": "F246"
            }
          ],
          "links": [
            {
              "label": "GitHub",
              "href": "https://github.com/kevincar/bless"
            },
            {
              "label": "PyPI",
              "href": "https://pypi.org/project/bless"
            },
            {
              "label": "Docs",
              "href": "https://api.github.com/repos/kevincar/bless/contents/bless/backends/server.py?ref=v0.3.0"
            }
          ],
          "what": [
            {
              "t": "fact",
              "fact": "F35"
            }
          ],
          "facts": [
            {
              "label": "Downloads / mo",
              "value": [
                {
                  "t": "fact",
                  "fact": "F247"
                }
              ]
            },
            {
              "label": "Stars",
              "value": [
                {
                  "t": "fact",
                  "fact": "F253"
                }
              ]
            },
            {
              "label": "Last release",
              "value": [
                {
                  "t": "fact",
                  "fact": "F249"
                }
              ]
            },
            {
              "label": "License",
              "value": [
                {
                  "t": "fact",
                  "fact": "F248"
                }
              ]
            },
            {
              "label": "Capabilities",
              "value": [
                {
                  "t": "link",
                  "href": "https://api.github.com/repos/kevincar/bless/contents/bless/backends/server.py?ref=v0.3.0",
                  "label": [
                    {
                      "t": "text",
                      "text": "From the "
                    },
                    {
                      "t": "fact",
                      "fact": "F246"
                    },
                    {
                      "t": "text",
                      "text": " docs"
                    }
                  ]
                }
              ]
            }
          ],
          "pros": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F36"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F37"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F38"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F39"
                }
              ]
            }
          ],
          "cons": [
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F40"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F41"
                }
              ]
            },
            {
              "lead": [
                {
                  "t": "fact",
                  "fact": "F42"
                }
              ],
              "body": [
                {
                  "t": "fact",
                  "fact": "F43"
                }
              ]
            }
          ],
          "tabs": [
            {
              "label": [
                {
                  "t": "fact",
                  "fact": "F259"
                }
              ],
              "stars": [
                {
                  "t": "fact",
                  "fact": "F260"
                }
              ],
              "usedBy": [
                {
                  "t": "link",
                  "href": "https://github.com/Jakeler/ble-serial",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F259"
                    }
                  ]
                },
                {
                  "t": "text",
                  "text": " "
                }
              ],
              "language": "python",
              "code": "async def setup_chars(self, service_uuid: str, write_uuid: str, read_uuid: str, mode: str, write_response_required: bool):\n    self.read_enabled = 'r' in mode\n    self.write_enabled = 'w' in mode\n\n    self.service_uuid = service_uuid\n    self.write_uuid = check_fill_empty(service_uuid, write_uuid, 'write')\n    self.read_uuid = check_fill_empty(service_uuid, read_uuid, 'read')\n\n    await self.server.add_new_service(self.service_uuid)\n    self.service = self.server.get_service(self.service_uuid)\n    logging.info(f'Service {self.service_uuid}')\n\n    if self.write_enabled:\n        # self.write_uuid = \"0000ffe1-0000-1000-8000-00805f9b34fb\"\n        char_flags = (\n            GATTCharacteristicProperties.write if write_response_required else\n            GATTCharacteristicProperties.write_without_response)\n        permissions = GATTAttributePermissions.readable | GATTAttributePermissions.writeable\n        await self.server.add_new_characteristic(self.service_uuid, self.write_uuid,\n            char_flags, None, permissions)\n\n        self.write_char = self.server.get_characteristic(self.write_uuid)\n        logging.info(f'Write characteristic: {str(self.write_char)}')\n    else:\n        logging.info('Writing disabled, no characteristic to setup')\n\n    if self.read_enabled:\n        char_flags = GATTCharacteristicProperties.read | GATTCharacteristicProperties.notify\n        permissions = GATTAttributePermissions.readable | GATTAttributePermissions.writeable\n        await self.server.add_new_characteristic(self.service_uuid, self.read_uuid,\n            char_flags, None, permissions)\n\n        self.read_char = self.server.get_characteristic(self.read_uuid)\n        logging.info(f'Read characteristic: {str(self.read_char)}')\n\n        self.data_read_done.set()\n    else:\n        logging.info('Reading disabled, no characteristic to setup')\n",
              "prov": [
                {
                  "t": "link",
                  "href": "https://github.com/Jakeler/ble-serial/blob/cf84f02cfa90dab81635a7e13afb34ccbb72db15/ble_serial/bluetooth/ble_server.py#L34-L71",
                  "label": [
                    {
                      "t": "fact",
                      "fact": "F258"
                    }
                  ]
                }
              ],
              "more": [
                {
                  "t": "link",
                  "href": "https://dashboard.exa.ai/playground/search?q=Real%20projects%20using%20bless%20for%20Bluetooth%20device%20communication&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D",
                  "label": [
                    {
                      "t": "text",
                      "text": "More projects using "
                    },
                    {
                      "t": "fact",
                      "fact": "F246"
                    },
                    {
                      "t": "text",
                      "text": " →"
                    }
                  ]
                }
              ]
            },
            {
              "label": [
                {
                  "t": "text",
                  "text": "Quickstart"
                }
              ],
              "language": "python",
              "code": "import asyncio\nfrom bless import BlessServer, GATTCharacteristicProperties, GATTAttributePermissions\n\nasync def main():\n    server = BlessServer(name=\"BLE example\")\n    service = \"0000180f-0000-1000-8000-00805f9b34fb\"\n    characteristic = \"00002a19-0000-1000-8000-00805f9b34fb\"\n    await server.add_new_service(service)\n    await server.add_new_characteristic(service, characteristic, GATTCharacteristicProperties.read, bytearray([100]), GATTAttributePermissions.readable)\n    server.read_request_func = lambda item, **kwargs: item.value\n    await server.start()\n    try:\n        await asyncio.sleep(5)\n    finally:\n        await server.stop()\n\nasyncio.run(main())\n",
              "prov": [
                {
                  "t": "text",
                  "text": "From "
                },
                {
                  "t": "link",
                  "href": "https://github.com/kevincar/bless/blob/3d639708c373a31de746d5cefe6ab512e3887386/bless/backends/server.py",
                  "label": [
                    {
                      "t": "text",
                      "text": "server.py"
                    }
                  ]
                }
              ]
            }
          ],
          "install": [
            {
              "t": "fact",
              "fact": "F251"
            }
          ]
        }
      ]
    }
  ],
  "questions": [
    {
      "q": "Which Python Bluetooth library should I use?",
      "a": [
        {
          "t": "link",
          "href": "#bleak",
          "label": [
            {
              "t": "text",
              "text": "Bleak"
            }
          ]
        },
        {
          "t": "text",
          "text": " suits cross-platform Bluetooth Low Energy clients with asyncio. "
        },
        {
          "t": "link",
          "href": "#bless",
          "label": [
            {
              "t": "text",
              "text": "Bless"
            }
          ]
        },
        {
          "t": "text",
          "text": " suits code that must act as a GATT server. "
        },
        {
          "t": "link",
          "href": "#bumble",
          "label": [
            {
              "t": "text",
              "text": "Bumble"
            }
          ]
        },
        {
          "t": "text",
          "text": " suits emulation and testing with a full Bluetooth stack in Python."
        }
      ]
    },
    {
      "q": "What is Bleak?",
      "a": [
        {
          "t": "link",
          "href": "#bleak",
          "label": [
            {
              "t": "text",
              "text": "Bleak"
            }
          ]
        },
        {
          "t": "text",
          "text": " is an asynchronous Bluetooth Low Energy client for Windows, macOS, and Linux. It scans for devices and reads, writes, and subscribes to GATT characteristics."
        }
      ]
    },
    {
      "q": "How do I use Bluetooth on a Raspberry Pi with Python?",
      "a": [
        {
          "t": "link",
          "href": "#bleak",
          "label": [
            {
              "t": "text",
              "text": "Bleak"
            }
          ]
        },
        {
          "t": "text",
          "text": " runs on Raspberry Pi OS through the BlueZ stack. Classic Bluetooth serial connections use the operating system's sockets instead."
        }
      ]
    }
  ],
  "facts": {
    "F1": {
      "label": "Library name, bleak",
      "display": "Bleak",
      "asOf": "2026-11-17"
    },
    "F2": {
      "label": "Monthly downloads, bleak",
      "display": "2.3M",
      "asOf": "2026-11-16"
    },
    "F3": {
      "label": "License, bleak",
      "display": "MIT",
      "asOf": "2026-11-17"
    },
    "F4": {
      "label": "Package release, bleak",
      "display": "3.1.0, Nov 2026",
      "asOf": "2026-11-07"
    },
    "F5": {
      "label": "Package release date, bleak",
      "display": "Nov 2026",
      "asOf": "2026-11-07"
    },
    "F6": {
      "label": "Repository stars, bleak",
      "display": "2.6K",
      "asOf": "2026-11-17"
    },
    "F7": {
      "label": "BLE GATT client, bleak",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F8": {
      "label": "Device discovery, bleak",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F9": {
      "label": "Asyncio API, bleak",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F10": {
      "label": "Install, bleak",
      "display": "pip install bleak",
      "asOf": "2026-11-17"
    },
    "F11": {
      "label": "What it does, bleak",
      "display": "Connects to Bluetooth Low Energy devices as an asynchronous GATT client.",
      "asOf": "2026-11-17"
    },
    "F12": {
      "label": "strengths lead, bleak",
      "display": "Cleans up managed connections",
      "asOf": "2026-11-17"
    },
    "F13": {
      "label": "strengths, bleak",
      "display": "An async context manager connects and disconnects the client.",
      "asOf": "2026-11-17"
    },
    "F14": {
      "label": "strengths lead, bleak",
      "display": "Reads and subscribes to characteristics",
      "asOf": "2026-11-17"
    },
    "F15": {
      "label": "strengths, bleak",
      "display": "Read values, write values, or receive GATT notifications.",
      "asOf": "2026-11-17"
    },
    "F16": {
      "label": "limitations lead, bleak",
      "display": "Classic RFCOMM needs another library",
      "asOf": "2026-11-17"
    },
    "F17": {
      "label": "limitations, bleak",
      "display": "Bleak handles BLE GATT rather than classic RFCOMM sockets.",
      "asOf": "2026-11-17"
    },
    "F18": {
      "label": "limitations lead, bleak",
      "display": "Address-based connections trigger discovery",
      "asOf": "2026-11-17"
    },
    "F19": {
      "label": "limitations, bleak",
      "display": "Pass a discovered BLEDevice when connecting to multiple devices.",
      "asOf": "2026-11-17"
    },
    "F20": {
      "label": "Quickstart, bleak",
      "display": "import asyncio\nfrom bleak import BleakClient\n\naddress = \"24:71:89:cc:09:05\"\nMODEL_NBR_UUID = \"2A24\"\n\nasync def main(address):\n    async with BleakClient(address) as client:\n        model_number = await client.read_gatt_char(MODEL_NBR_UUID)\n        print(f\"Model Number: {model_number.decode()}\")\n\nasyncio.run(main(address))\n\n",
      "asOf": "2026-11-17"
    },
    "F21": {
      "label": "Project function, bleak",
      "display": "async def _async_see_update_ble_battery(\n    mac: str,\n    now: datetime,\n    service_info: bluetooth.BluetoothServiceInfoBleak,\n) -> None:\n    \"\"\"Lookup Bluetooth LE devices and update status.\"\"\"\n    battery = None\n    # We need one we can connect to since the tracker will\n    # accept devices from non-connectable sources\n    if service_info.connectable:\n        device = service_info.device\n    elif connectable_device := bluetooth.async_ble_device_from_address(\n        hass, service_info.device.address, True\n    ):\n        device = connectable_device\n    else:\n        # The device can be seen by a passive tracker but we\n        # don't have a route to make a connection\n        return\n    try:\n        async with BleakClient(device) as client:\n            bat_char = await client.read_gatt_char(BATTERY_CHARACTERISTIC_UUID)\n            battery = ord(bat_char)\n    except TimeoutError:\n        _LOGGER.debug(\n            \"Timeout when trying to get battery status for %s\", service_info.name\n        )\n    # Bleak currently has a few places where checking dbus attributes\n    # can raise when there is another error. We need to trap AttributeError\n    # until bleak releases v0.15+ which resolves these.\n    except (AttributeError, BleakError) as err:\n        _LOGGER.debug(\"Could not read battery status: %s\", err)\n        # If the device does not offer battery information,\n        # there is no point in asking again later on.\n        # Remove the device from the battery-tracked\n        # devices, so that their battery is not wasted\n        # trying to get an unavailable information.\n        del devs_track_battery[mac]\n    if battery:\n        await async_see_device(mac, service_info.name, battery=battery)\n",
      "asOf": "2026-11-17"
    },
    "F22": {
      "label": "Project function reference, bleak",
      "display": "device_tracker.py · _async_see_update_ble_battery()",
      "asOf": "2026-11-17"
    },
    "F23": {
      "label": "Project repository, bleak",
      "display": "home-assistant/core",
      "asOf": "2026-11-17"
    },
    "F24": {
      "label": "Project stars, home-assistant/core",
      "display": "92.3K",
      "asOf": "2026-11-17"
    },
    "F25": {
      "label": "Project push date, home-assistant/core",
      "display": "Nov 2026",
      "asOf": "2026-11-16"
    },
    "F26": {
      "label": "Library name, bless",
      "display": "Bless",
      "asOf": "2026-11-17"
    },
    "F27": {
      "label": "Monthly downloads, bless",
      "display": "31.5K",
      "asOf": "2026-11-16"
    },
    "F28": {
      "label": "License, bless",
      "display": "MIT",
      "asOf": "2026-11-17"
    },
    "F29": {
      "label": "Package release, bless",
      "display": "0.3.0, Dec 2025",
      "asOf": "2025-12-23"
    },
    "F30": {
      "label": "Package release date, bless",
      "display": "Dec 2025",
      "asOf": "2025-12-23"
    },
    "F31": {
      "label": "Repository stars, bless",
      "display": "197",
      "asOf": "2026-11-17"
    },
    "F32": {
      "label": "BLE GATT server, bless",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F33": {
      "label": "Asyncio API, bless",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F34": {
      "label": "Install, bless",
      "display": "pip install bless",
      "asOf": "2026-11-17"
    },
    "F35": {
      "label": "What it does, bless",
      "display": "Creates a Bluetooth Low Energy GATT server with custom services and characteristics.",
      "asOf": "2026-11-17"
    },
    "F36": {
      "label": "strengths lead, bless",
      "display": "Serves custom BLE characteristics",
      "asOf": "2026-11-17"
    },
    "F37": {
      "label": "strengths, bless",
      "display": "Define services and characteristics for BLE clients to read or write.",
      "asOf": "2026-11-17"
    },
    "F38": {
      "label": "strengths lead, bless",
      "display": "Routes callbacks per characteristic",
      "asOf": "2026-11-17"
    },
    "F39": {
      "label": "strengths, bless",
      "display": "Override a characteristic callback before falling back to server-wide handling.",
      "asOf": "2026-11-17"
    },
    "F40": {
      "label": "limitations lead, bless",
      "display": "Writes need explicit callbacks",
      "asOf": "2026-11-17"
    },
    "F41": {
      "label": "limitations, bless",
      "display": "Define a write callback to handle incoming values.",
      "asOf": "2026-11-17"
    },
    "F42": {
      "label": "limitations lead, bless",
      "display": "Windows needs another setup package",
      "asOf": "2026-11-17"
    },
    "F43": {
      "label": "limitations, bless",
      "display": "Install pysetupdi alongside Bless on Windows.",
      "asOf": "2026-11-17"
    },
    "F44": {
      "label": "Quickstart, bless",
      "display": "\"\"\"\nExample for a BLE 4.0 Server\n\"\"\"\n\nimport sys\nimport logging\nimport asyncio\nimport threading\n\nfrom typing import Any, Union\n\nfrom bless import (  # type: ignore\n    BlessServer,\n    BlessGATTCharacteristic,\n    GATTCharacteristicProperties,\n    GATTAttributePermissions,\n)\n\nlogging.basicConfig(level=logging.DEBUG)\nlogger = logging.getLogger(name=__name__)\n\n# NOTE: Some systems require different synchronization methods.\ntrigger: Union[asyncio.Event, threading.Event]\nif sys.platform in [\"darwin\", \"win32\"]:\n    trigger = threading.Event()\nelse:\n    trigger = asyncio.Event()\n\n\ndef read_request(characteristic: BlessGATTCharacteristic, **kwargs) -> bytearray:\n    logger.debug(f\"Reading {characteristic.value}\")\n    return characteristic.value\n\n\ndef write_request(characteristic: BlessGATTCharacteristic, value: Any, **kwargs):\n    characteristic.value = value\n    logger.debug(f\"Char value set to {characteristic.value}\")\n    if characteristic.value == b\"\\x0f\":\n        logger.debug(\"NICE\")\n        trigger.set()\n\n\nasync def run(loop):\n    trigger.clear()\n    # Instantiate the server\n    my_service_name = \"Test Service\"\n    server = BlessServer(name=my_service_name, loop=loop)\n    server.read_request_func = read_request\n    server.write_request_func = write_request\n\n    # Add Service\n    my_service_uuid = \"A07498CA-AD5B-474E-940D-16F1FBE7E8CD\"\n    await server.add_new_service(my_service_uuid)\n\n    # Add a Characteristic to the service\n    my_char_uuid = \"51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B\"\n    char_flags = (\n        GATTCharacteristicProperties.read\n        | GATTCharacteristicProperties.write\n        | GATTCharacteristicProperties.indicate\n    )\n    permissions = GATTAttributePermissions.readable | GATTAttributePermissions.writable\n    await server.add_new_characteristic(\n        my_service_uuid, my_char_uuid, char_flags, None, permissions\n    )\n\n    logger.debug(server.get_characteristic(my_char_uuid))\n    await server.start()\n    logger.debug(\"Advertising\")\n    logger.info(f\"Write '0xF' to the advertised characteristic: {my_char_uuid}\")\n    if trigger.__module__ == \"threading\":\n        trigger.wait()\n    else:\n        await trigger.wait()\n\n    await asyncio.sleep(2)\n    logger.debug(\"Updating\")\n    server.get_characteristic(my_char_uuid)\n    server.update_value(my_service_uuid, \"51FF12BB-3ED8-46E5-B4F9-D64E2FEC021B\")\n    await asyncio.sleep(5)\n    await server.stop()\n\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(run(loop))\n",
      "asOf": "2026-11-17"
    },
    "F45": {
      "label": "Library name, PyBluez",
      "display": "PyBluez",
      "asOf": "2026-11-17"
    },
    "F46": {
      "label": "Monthly downloads, PyBluez",
      "display": "17.6K",
      "asOf": "2026-11-16"
    },
    "F47": {
      "label": "License, PyBluez",
      "display": "GPL",
      "asOf": "2026-11-17"
    },
    "F48": {
      "label": "Package release, PyBluez",
      "display": "0.23, Dec 2019",
      "asOf": "2019-12-28"
    },
    "F49": {
      "label": "Package release date, PyBluez",
      "display": "Dec 2019",
      "asOf": "2019-12-28"
    },
    "F50": {
      "label": "Repository stars, PyBluez",
      "display": "2.4K",
      "asOf": "2026-11-17"
    },
    "F51": {
      "label": "BLE GATT client, PyBluez",
      "display": "Via plugin",
      "asOf": "2026-11-17"
    },
    "F52": {
      "label": "Device discovery, PyBluez",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F53": {
      "label": "Install, PyBluez",
      "display": "pip install PyBluez",
      "asOf": "2026-11-17"
    },
    "F54": {
      "label": "What it does, PyBluez",
      "display": "Exposes classic Bluetooth discovery, services, and sockets with an optional BLE bridge.",
      "asOf": "2026-11-17"
    },
    "F55": {
      "label": "strengths lead, PyBluez",
      "display": "Provides classic RFCOMM sockets",
      "asOf": "2026-11-17"
    },
    "F56": {
      "label": "strengths, PyBluez",
      "display": "Discover a service and open its RFCOMM connection.",
      "asOf": "2026-11-17"
    },
    "F57": {
      "label": "strengths lead, PyBluez",
      "display": "Discovers nearby named devices",
      "asOf": "2026-11-17"
    },
    "F58": {
      "label": "strengths, PyBluez",
      "display": "Request device names during Bluetooth discovery.",
      "asOf": "2026-11-17"
    },
    "F59": {
      "label": "limitations lead, PyBluez",
      "display": "Upstream development has stopped",
      "asOf": "2026-11-17"
    },
    "F60": {
      "label": "limitations, PyBluez",
      "display": "Consider a maintained alternative for new Bluetooth integrations.",
      "asOf": "2026-11-17"
    },
    "F61": {
      "label": "limitations lead, PyBluez",
      "display": "BLE support is experimental",
      "asOf": "2026-11-17"
    },
    "F62": {
      "label": "limitations, PyBluez",
      "display": "The optional BLE support is limited to Linux.",
      "asOf": "2026-11-17"
    },
    "F63": {
      "label": "Quickstart, PyBluez",
      "display": "#!/usr/bin/env python3\n\"\"\"PyBluez simple example rfcomm-client.py\n\nSimple demonstration of a client application that uses RFCOMM sockets intended\nfor use with rfcomm-server.\n\nAuthor: Albert Huang <albert@csail.mit.edu>\n$Id: rfcomm-client.py 424 2006-08-24 03:35:54Z albert $\n\"\"\"\n\nimport sys\n\nimport bluetooth\n\n\naddr = None\n\nif len(sys.argv) < 2:\n    print(\"No device specified. Searching all nearby bluetooth devices for \"\n          \"the SampleServer service...\")\nelse:\n    addr = sys.argv[1]\n    print(\"Searching for SampleServer on {}...\".format(addr))\n\n# search for the SampleServer service\nuuid = \"94f39d29-7d6d-437d-973b-fba39e49d4ee\"\nservice_matches = bluetooth.find_service(uuid=uuid, address=addr)\n\nif len(service_matches) == 0:\n    print(\"Couldn't find the SampleServer service.\")\n    sys.exit(0)\n\nfirst_match = service_matches[0]\nport = first_match[\"port\"]\nname = first_match[\"name\"]\nhost = first_match[\"host\"]\n\nprint(\"Connecting to \\\"{}\\\" on {}\".format(name, host))\n\n# Create the client socket\nsock = bluetooth.BluetoothSocket(bluetooth.RFCOMM)\nsock.connect((host, port))\n\nprint(\"Connected. Type something...\")\nwhile True:\n    data = input()\n    if not data:\n        break\n    sock.send(data)\n\nsock.close()\n",
      "asOf": "2026-11-17"
    },
    "F64": {
      "label": "Project function, PyBluez",
      "display": "def _perform_query_fastpair(self) -> dict[str, int]:\n    \"\"\"\n    Will try to get the battery level of supported devices over the Nearby/Fast Pair protocol.\n    \"\"\"\n    result: dict[str, int] = {}\n    sock = RFCOMMSocket()\n    logger.debug(\"Connecting to {}.{} (Nearby/Fast Pair)\".format(self._bluetooth_mac, self._fastpair_port))\n    sock.connect((self._bluetooth_mac, self._fastpair_port))\n    logger.debug(\"Connected\")\n\n    try:\n        for data in sock:\n            while len(data) > 0:\n                # Header format https://developers.google.com/nearby/fast-pair/specifications/extensions/messagestream\n                if len(data) < 4:\n                    logger.debug(\"Invalid data\")\n                    return result\n\n                group = data[0]\n                code = data[1]\n                length = int.from_bytes(data[2:4], \"big\")\n                payload = data[4:4+length+1]\n                logger.debug(\"Group: {}; Code: {}; Length: {}; Payload: {}\".format(group, code, length, payload.hex()))\n\n                # See https://github.com/google/nearby/blob/main/fastpair/message_stream/message.h\n                # DeviceInformationEvent group, BatteryUpdated code.\n                if group == 3 and code == 3:\n                    # Example: https://github.com/google/nearby/blob/main/fastpair/common/battery_notification.cc\n                    def parse_level(level: int) -> int:\n                        #   01234567 bits order\n                        # 0x11111111 charging, but not present/unknown battery level charging\n                        # 0x01111111 not charging, but not present/unknown battery level\n                        # 0 bit:    1 charging, 0 not charging\n                        # 1-7 bits: battery level \n                        if (level & 0x7f) == 0x7f:\n                            return None\n                        # Top bit indicates if the device is charging\n                        return level & 0x7f\n\n                    if len(payload) == 1:\n                        result[\"overall\"] = parse_level(payload[0])\n                    elif len(payload) == 3:\n                        result[\"left\"] = parse_level(payload[0])\n                        result[\"right\"] = parse_level(payload[1])\n                        result[\"case\"] = parse_level(payload[2])\n                    else:\n                        raise BatteryQueryError(\"Invalid number of data points in Fast Pair packet.\")\n                    break\n\n                # Parse next packet\n                data = data[4+length:]\n            if len(result) > 0:\n                break\n\n        sock.close()\n    except bluetooth.BluetoothError as e:\n        # Fast Pair errors are not fatal.\n        logger.info(\"Bluetooth Error while reading Nearby/Fast Pair data: \" + str(e))\n        pass\n    logger.debug(\"Nearby/Fast Pair query results: \" + str(result))\n    return result\n",
      "asOf": "2026-11-17"
    },
    "F65": {
      "label": "Project function reference, PyBluez",
      "display": "bluetooth_battery.py · _perform_query_fastpair()",
      "asOf": "2026-11-17"
    },
    "F66": {
      "label": "Project repository, PyBluez",
      "display": "TheWeirdDev/Bluetooth_Headset_Battery_Level",
      "asOf": "2026-11-17"
    },
    "F67": {
      "label": "Project stars, TheWeirdDev/Bluetooth_Headset_Battery_Level",
      "display": "785",
      "asOf": "2026-11-17"
    },
    "F68": {
      "label": "Project push date, TheWeirdDev/Bluetooth_Headset_Battery_Level",
      "display": "Apr 2024",
      "asOf": "2024-04-21"
    },
    "F69": {
      "label": "Library name, bluepy",
      "display": "bluepy",
      "asOf": "2026-11-17"
    },
    "F70": {
      "label": "Monthly downloads, bluepy",
      "display": "15.9K",
      "asOf": "2026-11-16"
    },
    "F71": {
      "label": "License, bluepy",
      "display": "GPLv2 / public domain",
      "asOf": "2026-11-17"
    },
    "F72": {
      "label": "Package release, bluepy",
      "display": "1.3.0, Dec 2018",
      "asOf": "2018-12-03"
    },
    "F73": {
      "label": "Package release date, bluepy",
      "display": "Dec 2018",
      "asOf": "2018-12-03"
    },
    "F74": {
      "label": "Repository stars, bluepy",
      "display": "1.6K",
      "asOf": "2026-11-17"
    },
    "F75": {
      "label": "BLE GATT client, bluepy",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F76": {
      "label": "BLE GATT server, bluepy",
      "display": "Unsupported",
      "asOf": "2026-11-17"
    },
    "F77": {
      "label": "Device discovery, bluepy",
      "display": "Built-in",
      "asOf": "2026-11-17"
    },
    "F78": {
      "label": "Install, bluepy",
      "display": "pip install bluepy",
      "asOf": "2026-11-17"
    },
    "F79": {
      "label": "What it does, bluepy",
      "display": "Scans and connects to Bluetooth Low Energy devices on Linux.",
      "asOf": "2026-11-17"
    },
    "F80": {
      "label": "strengths lead, bluepy",
      "display": "Exposes advertising data",
      "asOf": "2026-11-17"
    },
    "F81": {
      "label": "strengths, bluepy",
      "display": "Scanner returns discovered devices with their advertising data.",
      "asOf": "2026-11-17"
    },
    "F82": {
      "label": "strengths lead, bluepy",
      "display": "Handles GATT notifications through callbacks",
      "asOf": "2026-11-17"
    },
    "F83": {
      "label": "strengths, bluepy",
      "display": "Register a delegate and wait for characteristic notifications.",
      "asOf": "2026-11-17"
    },
    "F84": {
      "label": "limitations lead, bluepy",
      "display": "Runs on Linux only",
      "asOf": "2026-11-17"
    },
    "F85": {
      "label": "limitations, bluepy",
      "display": "Use another library for Windows or macOS.",
      "asOf": "2026-11-17"
    },
    "F86": {
      "label": "limitations lead, bluepy",
      "display": "Needs a compiled native helper",
      "asOf": "2026-11-17"
    },
    "F87": {
      "label": "limitations, bluepy",
      "display": "Installation builds bluepy-helper from C source.",
      "asOf": "2026-11-17"
    },
    "F88": {
      "label": "Quickstart, bluepy",
      "display": "#!/usr/bin/python\nfrom __future__ import print_function\n\nfrom time import gmtime, strftime, sleep\nfrom bluepy.btle import Scanner, DefaultDelegate, BTLEException\nimport sys\n\n\nclass ScanDelegate(DefaultDelegate):\n\n    def handleDiscovery(self, dev, isNewDev, isNewData):\n        print(strftime(\"%Y-%m-%d %H:%M:%S\", gmtime()), dev.addr, dev.getScanData())\n        sys.stdout.flush()\n\nscanner = Scanner().withDelegate(ScanDelegate())\n\n# listen for ADV_IND packages for 10s, then exit\nscanner.scan(10.0, passive=True)\n",
      "asOf": "2026-11-17"
    },
    "F89": {
      "label": "Project function, bluepy",
      "display": "def status_update(self):\n    from bluepy import btle\n\n    if self.passive:\n        scanner = btle.Scanner()\n        results = scanner.scan(self.scan_timeout if hasattr(self, 'scan_timeout') else 20.0, passive=True)\n\n        for res in results:\n            device = self.find_device(res.addr)\n            if device:\n                for (adtype, desc, value) in res.getScanData():\n                    if (\"1a18\" in value):\n                        _LOGGER.debug(\"%s - received scan data %s\", res.addr, value)\n                        device.processScanValue(value)\n\n    for name, lywsd03mmc in self.devices.items():\n        try:\n            ret = lywsd03mmc.readAll()\n        except btle.BTLEDisconnectError as e:\n            self.log_connect_exception(_LOGGER, name, e)\n        except btle.BTLEException as e:\n            self.log_unspecified_exception(_LOGGER, name, e)\n        else:\n            yield [MqttMessage(topic=self.format_topic(name), payload=json.dumps(ret))]\n",
      "asOf": "2026-11-17"
    },
    "F90": {
      "label": "Project function reference, bluepy",
      "display": "lywsd03mmc.py · status_update()",
      "asOf": "2026-11-17"
    },
    "F91": {
      "label": "Project repository, bluepy",
      "display": "zewelor/bt-mqtt-gateway",
      "asOf": "2026-11-17"
    },
    "F92": {
      "label": "Project stars, zewelor/bt-mqtt-gateway",
      "display": "550",
      "asOf": "2026-11-17"
    },
    "F93": {
      "label": "Project push date, zewelor/bt-mqtt-gateway",
      "display": "Oct 2023",
      "asOf": "2023-10-26"
    },
    "F94": {
      "label": "Developer need",
      "display": "Asynchronous BLE client connections",
      "asOf": "2026-11-17"
    },
    "F95": {
      "label": "Why choose bleak",
      "display": "managed async connections and disconnections",
      "asOf": "2026-11-17"
    },
    "F96": {
      "label": "Developer need in introduction",
      "display": "asynchronous BLE client connections",
      "asOf": "2026-11-17"
    },
    "F97": {
      "label": "When to consider PyBluez",
      "display": "the device requires a classic RFCOMM socket",
      "asOf": "2026-11-17"
    },
    "F98": {
      "label": "Developer need",
      "display": "Linux advertising-data scans",
      "asOf": "2026-11-17"
    },
    "F99": {
      "label": "Why choose bluepy",
      "display": "scanning nearby BLE advertising data",
      "asOf": "2026-11-17"
    },
    "F100": {
      "label": "Developer need in introduction",
      "display": "linux advertising-data scans",
      "asOf": "2026-11-17"
    },
    "F101": {
      "label": "Developer need",
      "display": "Classic RFCOMM connections",
      "asOf": "2026-11-17"
    },
    "F102": {
      "label": "Why choose PyBluez",
      "display": "opening classic RFCOMM sockets",
      "asOf": "2026-11-17"
    },
    "F103": {
      "label": "Developer need in introduction",
      "display": "classic RFCOMM connections",
      "asOf": "2026-11-17"
    },
    "F104": {
      "label": "When to consider bleak",
      "display": "the task is BLE characteristic I/O",
      "asOf": "2026-11-17"
    },
    "F105": {
      "label": "Developer need",
      "display": "Custom BLE GATT servers",
      "asOf": "2026-11-17"
    },
    "F106": {
      "label": "Why choose bless",
      "display": "serving custom characteristics to clients",
      "asOf": "2026-11-17"
    },
    "F107": {
      "label": "Developer need in introduction",
      "display": "custom BLE GATT servers",
      "asOf": "2026-11-17"
    },
    "F108": {
      "label": "Page introduction",
      "display": "Python Bluetooth libraries let device developers communicate with Bluetooth devices.",
      "asOf": "2026-11-17"
    },
    "F109": {
      "label": "FAQ: Which Python Bluetooth library fits each device role?",
      "display": "Bleak is a GATT client for communicating with BLE servers.",
      "asOf": "2026-11-17"
    },
    "F110": {
      "label": "FAQ: Which Python Bluetooth library fits each device role?",
      "display": "bluepy provides Linux BLE access.",
      "asOf": "2026-11-17"
    },
    "F111": {
      "label": "FAQ: Which Python Bluetooth library fits each device role?",
      "display": "PyBluez exposes classic RFCOMM sockets.",
      "asOf": "2026-11-17"
    },
    "F112": {
      "label": "FAQ: Which Python Bluetooth library fits each device role?",
      "display": "Bless creates custom GATT servers for BLE clients.",
      "asOf": "2026-11-17"
    },
    "F113": {
      "label": "FAQ: Can Bleak open a classic RFCOMM connection?",
      "display": "The maintainer explicitly limits Bleak to BLE GATT and excludes RFCOMM.",
      "asOf": "2026-11-17"
    },
    "F114": {
      "label": "FAQ: Does a BLE GATT client also create a peripheral server?",
      "display": "Bleak connects as a client to devices acting as GATT servers.",
      "asOf": "2026-11-17"
    },
    "F115": {
      "label": "FAQ: Does a BLE GATT client also create a peripheral server?",
      "display": "Bless provides the server role with user-defined services and characteristics.",
      "asOf": "2026-11-17"
    },
    "F116": {
      "label": "FAQ: Does a BLE GATT client also create a peripheral server?",
      "display": "bluepy lists peripheral-role support among missing features.",
      "asOf": "2026-11-17"
    },
    "F117": {
      "label": "FAQ: Why use a discovered BLEDevice instead of its address?",
      "display": "An address or UUID makes Bleak connect perform implicit device discovery.",
      "asOf": "2026-11-17"
    },
    "F118": {
      "label": "FAQ: Why use a discovered BLEDevice instead of its address?",
      "display": "The behavior is a known source of concurrent-connection problems.",
      "asOf": "2026-11-17"
    },
    "F119": {
      "label": "FAQ: Does macOS expose a device Bluetooth MAC address to Bleak?",
      "display": "macOS supplies a device UUID instead of exposing its Bluetooth address.",
      "asOf": "2026-11-17"
    },
    "F120": {
      "label": "FAQ: Can Bleak operations use separate asyncio.run calls?",
      "display": "Bleak requires the same continuously running asyncio loop for all operations.",
      "asOf": "2026-11-17"
    },
    "F121": {
      "label": "FAQ: Does bluepy run on Windows or macOS?",
      "display": "Its own project states that bluepy runs on Linux only.",
      "asOf": "2026-11-17"
    },
    "F122": {
      "label": "FAQ: Is PyBluez still under active development?",
      "display": "The repository explicitly states that the project is not under development.",
      "asOf": "2026-11-17"
    },
    "F123": {
      "label": "FAQ: Is PyBluez BLE support available on every supported desktop platform?",
      "display": "Experimental BLE support is Linux-only and uses optional dependencies.",
      "asOf": "2026-11-17"
    },
    "F124": {
      "label": "FAQ: Is PyBluez BLE support available on every supported desktop platform?",
      "display": "Its bluetooth.ble module re-exports gattlib.",
      "asOf": "2026-11-17"
    },
    "F125": {
      "label": "FAQ: Does waiting for bluepy notifications return immediately?",
      "display": "waitForNotifications blocks until a notification arrives or its timeout expires.",
      "asOf": "2026-11-17"
    },
    "F126": {
      "label": "FAQ: Does a default Bless server store every incoming write?",
      "display": "Default read handling returns the characteristic value.",
      "asOf": "2026-11-17"
    },
    "F127": {
      "label": "FAQ: Does a default Bless server store every incoming write?",
      "display": "Writes, subscriptions, and unsubscriptions are no-ops unless callbacks are defined.",
      "asOf": "2026-11-17"
    },
    "F128": {
      "label": "FAQ: Does discovering an advertisement guarantee a connection is possible?",
      "display": "bluepy warns that devices can advertise without accepting connections, or accept connections without advertising.",
      "asOf": "2026-11-17"
    },
    "F129": {
      "label": "Library name, bleak",
      "display": "Bleak",
      "asOf": "2026-11-20"
    },
    "F130": {
      "label": "Monthly downloads, bleak",
      "display": "2.4M",
      "asOf": "2026-11-20"
    },
    "F131": {
      "label": "License, bleak",
      "display": "MIT",
      "asOf": "2026-11-20"
    },
    "F132": {
      "label": "Package release, bleak",
      "display": "3.1.0",
      "asOf": "2026-11-20"
    },
    "F133": {
      "label": "Package release date, bleak",
      "display": "Nov 2026",
      "asOf": "2026-11-20"
    },
    "F134": {
      "label": "Install, bleak",
      "display": "python3.11 -m pip install bleak==3.1.0",
      "asOf": "2026-11-20"
    },
    "F135": {
      "label": "Quickstart, bleak",
      "display": "import asyncio\nfrom bleak import BleakScanner\n\nasync def main():\n    print(await BleakScanner.discover())\n\nasyncio.run(main())\n",
      "asOf": "2026-11-20"
    },
    "F136": {
      "label": "Repository stars, bleak",
      "display": "2.6K",
      "asOf": "2026-11-20"
    },
    "F137": {
      "label": "Local GATT server, bleak",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F138": {
      "label": "Classic RFCOMM stack, bleak",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F139": {
      "label": "Bluetooth role and hardware boundary, bleak",
      "display": "Cross-platform asyncio BLE GATT client/discovery; reading, writing, and notification subscription on remote devices.",
      "asOf": "2026-11-20"
    },
    "F140": {
      "label": "Project function, bleak",
      "display": "async def _async_see_update_ble_battery(\n    mac: str,\n    now: datetime,\n    service_info: bluetooth.BluetoothServiceInfoBleak,\n) -> None:\n    \"\"\"Lookup Bluetooth LE devices and update status.\"\"\"\n    battery = None\n    # We need one we can connect to since the tracker will\n    # accept devices from non-connectable sources\n    if service_info.connectable:\n        device = service_info.device\n    elif connectable_device := bluetooth.async_ble_device_from_address(\n        hass, service_info.device.address, True\n    ):\n        device = connectable_device\n    else:\n        # The device can be seen by a passive tracker but we\n        # don't have a route to make a connection\n        return\n    try:\n        async with BleakClient(device) as client:\n            bat_char = await client.read_gatt_char(BATTERY_CHARACTERISTIC_UUID)\n            battery = ord(bat_char)\n    except TimeoutError:\n        _LOGGER.debug(\n            \"Timeout when trying to get battery status for %s\", service_info.name\n        )\n    # Bleak currently has a few places where checking dbus attributes\n    # can raise when there is another error. We need to trap AttributeError\n    # until bleak releases v0.15+ which resolves these.\n    except (AttributeError, BleakError) as err:\n        _LOGGER.debug(\"Could not read battery status: %s\", err)\n        # If the device does not offer battery information,\n        # there is no point in asking again later on.\n        # Remove the device from the battery-tracked\n        # devices, so that their battery is not wasted\n        # trying to get an unavailable information.\n        del devs_track_battery[mac]\n    if battery:\n        await async_see_device(mac, service_info.name, battery=battery)",
      "asOf": "2026-11-20"
    },
    "F141": {
      "label": "Project source file, bleak",
      "display": "homeassistant/components/bluetooth_le_tracker/device_tracker.py",
      "asOf": "2026-11-20"
    },
    "F142": {
      "label": "Project full_name, bleak",
      "display": "home-assistant/core",
      "asOf": "2026-11-20"
    },
    "F143": {
      "label": "Project stargazers_count, bleak",
      "display": "92.3K",
      "asOf": "2026-11-20"
    },
    "F144": {
      "label": "Library name, habluetooth",
      "display": "habluetooth",
      "asOf": "2026-11-20"
    },
    "F145": {
      "label": "Monthly downloads, habluetooth",
      "display": "1.3M",
      "asOf": "2026-11-20"
    },
    "F146": {
      "label": "License, habluetooth",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F147": {
      "label": "Package release, habluetooth",
      "display": "7.1.3",
      "asOf": "2026-11-20"
    },
    "F148": {
      "label": "Package release date, habluetooth",
      "display": "Nov 2026",
      "asOf": "2026-11-20"
    },
    "F149": {
      "label": "Install, habluetooth",
      "display": "python3.11 -m pip install habluetooth==7.1.3 bleak==3.1.0",
      "asOf": "2026-11-20"
    },
    "F150": {
      "label": "Quickstart, habluetooth",
      "display": "import asyncio\nfrom habluetooth import BluetoothManager\n\nasync def main():\n    manager = BluetoothManager()\n    await manager.async_setup()\n    try:\n        print(await manager.async_get_bluetooth_adapters())\n    finally:\n        manager.async_stop()\n\nasyncio.run(main())\n",
      "asOf": "2026-11-20"
    },
    "F151": {
      "label": "Official description, habluetooth",
      "display": "Provides high-availability Bluetooth management.",
      "asOf": "2026-11-20"
    },
    "F152": {
      "label": "Quickstart source file, habluetooth",
      "display": "manager.py",
      "asOf": "2026-11-20"
    },
    "F153": {
      "label": "Repository stars, habluetooth",
      "display": "24",
      "asOf": "2026-11-20"
    },
    "F154": {
      "label": "Local GATT server, habluetooth",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F155": {
      "label": "Classic RFCOMM stack, habluetooth",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F156": {
      "label": "Bluetooth role and hardware boundary, habluetooth",
      "display": "High-availability local/remote scanner coordination, device history, adapter recovery, and best connection-route selection for BLE hosts.",
      "asOf": "2026-11-20"
    },
    "F157": {
      "label": "Project function, habluetooth",
      "display": "async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:\n    \"\"\"Set up a config entry for a bluetooth scanner.\"\"\"\n    if source_entry_id := entry.data.get(CONF_SOURCE_CONFIG_ENTRY_ID):\n        if not (source_entry := hass.config_entries.async_get_entry(source_entry_id)):\n            # Cleanup the orphaned entry using a call_soon to ensure\n            # we can return before the entry is removed\n            hass.loop.call_soon(\n                hass_callback(\n                    lambda: hass.async_create_task(\n                        hass.config_entries.async_remove(entry.entry_id),\n                        \"remove orphaned bluetooth entry {entry.entry_id}\",\n                    )\n                )\n            )\n            return\n        address = entry.unique_id\n        assert address is not None\n        source_domain = entry.data[CONF_SOURCE_DOMAIN]\n        if mac_manufacturer := await get_manufacturer_from_mac(address):\n            manufacturer = f\"{mac_manufacturer} ({source_domain})\"\n        else:\n            manufacturer = source_domain\n        details = AdapterDetails(\n            address=address,\n            product=entry.data.get(CONF_SOURCE_MODEL),\n            manufacturer=manufacturer,\n        )\n        await async_update_device(\n            hass,\n            entry,\n            source_entry.title,\n            details,\n            entry.data.get(CONF_SOURCE_DEVICE_ID),\n        )\n        return\n    manager = _get_manager(hass)\n    address = entry.unique_id\n    assert address is not None\n    adapter = await manager.async_get_adapter_from_address_or_recover(address)\n    if adapter is None:\n        raise ConfigEntryNotReady(\n            f\"Bluetooth adapter {adapter} with address {address} not found\"\n        )\n    adapters = await manager.async_get_bluetooth_adapters()\n    details = adapters[adapter]\n    mode = resolve_scanning_mode(entry.options)\n    # AUTO needs passive scanning support to flip on demand; without it\n    # the scanner would start passive on hardware that can't do passive.\n    if mode is BluetoothScanningMode.AUTO and not details.get(ADAPTER_PASSIVE_SCAN):\n        mode = BluetoothScanningMode.ACTIVE\n    scanner = HaScanner(mode, adapter, address)\n    entry.async_on_unload(scanner.async_setup())\n    if entry.title == address:\n        hass.config_entries.async_update_entry(\n            entry, title=adapter_title(adapter, details)\n        )\n    slots: int = details.get(ADAPTER_CONNECTION_SLOTS) or DEFAULT_CONNECTION_SLOTS\n    # Register the scanner before starting so\n    # any raw advertisement data can be processed\n    entry.async_on_unload(async_register_scanner(hass, scanner, connection_slots=slots))\n    await async_update_device(hass, entry, adapter, details)\n    try:\n        await scanner.async_start()\n    except (RuntimeError, ScannerStartError) as err:\n        raise ConfigEntryNotReady(\n            f\"{adapter_human_name(adapter, address)}: {err}\"\n        ) from err\n    entry.async_on_unload(entry.add_update_listener(async_update_listener))\n    entry.async_on_unload(scanner.async_stop)",
      "asOf": "2026-11-20"
    },
    "F158": {
      "label": "Project source file, habluetooth",
      "display": "homeassistant/components/bluetooth/__init__.py",
      "asOf": "2026-11-20"
    },
    "F159": {
      "label": "Project full_name, habluetooth",
      "display": "home-assistant/core",
      "asOf": "2026-11-20"
    },
    "F160": {
      "label": "Project stargazers_count, habluetooth",
      "display": "92.3K",
      "asOf": "2026-11-20"
    },
    "F161": {
      "label": "Library name, bleak-retry-connector",
      "display": "Bleak Retry Connector",
      "asOf": "2026-11-20"
    },
    "F162": {
      "label": "Monthly downloads, bleak-retry-connector",
      "display": "852.4K",
      "asOf": "2026-11-20"
    },
    "F163": {
      "label": "License, bleak-retry-connector",
      "display": "MIT",
      "asOf": "2026-11-20"
    },
    "F164": {
      "label": "Package release, bleak-retry-connector",
      "display": "4.7.1",
      "asOf": "2026-11-20"
    },
    "F165": {
      "label": "Package release date, bleak-retry-connector",
      "display": "Sep 2026",
      "asOf": "2026-11-20"
    },
    "F166": {
      "label": "Install, bleak-retry-connector",
      "display": "python3.11 -m pip install bleak-retry-connector==4.7.1 bleak==3.1.0",
      "asOf": "2026-11-20"
    },
    "F167": {
      "label": "Quickstart, bleak-retry-connector",
      "display": "import asyncio, os\nfrom bleak import BleakScanner\nfrom bleak_retry_connector import establish_connection, BleakClientWithServiceCache\n\nasync def main():\n    device = await BleakScanner.find_device_by_address(os.environ[\"BLE_ADDRESS\"])\n    if device is None:\n        raise RuntimeError(\"Device not found\")\n    client = await establish_connection(BleakClientWithServiceCache, device, device.name or device.address)\n    try:\n        print(client.services)\n    finally:\n        await client.disconnect()\n\nasyncio.run(main())\n",
      "asOf": "2026-11-20"
    },
    "F168": {
      "label": "Official description, bleak-retry-connector",
      "display": "Retries Bleak client connections after transient failures.",
      "asOf": "2026-11-20"
    },
    "F169": {
      "label": "Quickstart source file, bleak-retry-connector",
      "display": "usage.html",
      "asOf": "2026-11-20"
    },
    "F170": {
      "label": "Repository stars, bleak-retry-connector",
      "display": "28",
      "asOf": "2026-11-20"
    },
    "F171": {
      "label": "Local GATT server, bleak-retry-connector",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F172": {
      "label": "Classic RFCOMM stack, bleak-retry-connector",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F173": {
      "label": "Bluetooth role and hardware boundary, bleak-retry-connector",
      "display": "Bleak connection establishment with retry/backoff, connection-slot handling, and service-cache recovery.",
      "asOf": "2026-11-20"
    },
    "F174": {
      "label": "Project function, bleak-retry-connector",
      "display": "async def _ensure_connected(self):\n    \"\"\"Ensure connection to device is established.\"\"\"\n    if self._connect_lock.locked():\n        _LOGGER.debug(\n            \"%s: Connection already in progress, waiting for it to complete; RSSI: %s\",\n            self.name,\n            self.rssi,\n        )\n    if self._client and self._client.is_connected:\n        _LOGGER.debug(\n            \"%s: Already connected before obtaining lock, resetting timer; RSSI: %s\",\n            self.name,\n            self.rssi,\n        )\n        self._reset_disconnect_timer()\n        return\n    async with self._connect_lock:\n        # Check again while holding the lock\n        if self._client and self._client.is_connected:\n            _LOGGER.debug(\n                \"%s: Already connected after obtaining lock, resetting timer; RSSI: %s\",\n                self.name,\n                self.rssi,\n            )\n            self._reset_disconnect_timer()\n            return\n        _LOGGER.debug(\"%s: Connecting; RSSI: %s\", self.name, self.rssi)\n        client: BleakClientWithServiceCache = await establish_connection(\n            BleakClientWithServiceCache,\n            self._device,\n            self.name,\n            self._disconnected,\n            use_services_cache=True,\n            ble_device_callback=lambda: self._device,\n        )\n        _LOGGER.debug(\"%s: Connected; RSSI: %s\", self.name, self.rssi)\n        self._client = client\n\n        try:\n            self._resolve_characteristics(client.services)\n        except CharacteristicMissingError as ex:\n            _LOGGER.debug(\n                \"%s: characteristic missing, clearing cache: %s; RSSI: %s\",\n                self.name,\n                ex,\n                self.rssi,\n                exc_info=True,\n            )\n            await client.clear_cache()\n            self._cancel_disconnect_timer()\n            await self._execute_disconnect_with_lock()\n            raise\n\n        _LOGGER.debug(\n            \"%s: Starting notify and disconnect timer; RSSI: %s\",\n            self.name,\n            self.rssi,\n        )\n        self._reset_disconnect_timer()\n        await self._start_notify()",
      "asOf": "2026-11-20"
    },
    "F175": {
      "label": "Project source file, bleak-retry-connector",
      "display": "switchbot/devices/device.py",
      "asOf": "2026-11-20"
    },
    "F176": {
      "label": "Project full_name, bleak-retry-connector",
      "display": "sblibs/pySwitchbot",
      "asOf": "2026-11-20"
    },
    "F177": {
      "label": "Project stargazers_count, bleak-retry-connector",
      "display": "180",
      "asOf": "2026-11-20"
    },
    "F178": {
      "label": "Library name, bumble",
      "display": "Bumble",
      "asOf": "2026-11-20"
    },
    "F179": {
      "label": "Monthly downloads, bumble",
      "display": "169.1K",
      "asOf": "2026-11-20"
    },
    "F180": {
      "label": "License, bumble",
      "display": "Apache-2.0",
      "asOf": "2026-11-20"
    },
    "F181": {
      "label": "Package release, bumble",
      "display": "0.0.236",
      "asOf": "2026-11-20"
    },
    "F182": {
      "label": "Package release date, bumble",
      "display": "Oct 2026",
      "asOf": "2026-11-20"
    },
    "F183": {
      "label": "Install, bumble",
      "display": "python3.11 -m pip install bumble==0.0.236",
      "asOf": "2026-11-20"
    },
    "F184": {
      "label": "Quickstart, bumble",
      "display": "import asyncio, os\nfrom bumble.device import Device\nfrom bumble.hci import Address\nfrom bumble.transport import open_transport\n\nasync def main():\n    async with await open_transport(os.environ[\"BUMBLE_TRANSPORT\"]) as transport:\n        device = Device.with_hci(\"Bumble\", Address(\"F0:F1:F2:F3:F4:F5\"), transport.source, transport.sink)\n        await device.power_on()\n        await device.start_scanning()\n        await asyncio.sleep(5)\n        await device.stop_scanning()\n\nasyncio.run(main())\n",
      "asOf": "2026-11-20"
    },
    "F185": {
      "label": "Official description, bumble",
      "display": "Implements a Bluetooth stack for apps, emulation, and testing.",
      "asOf": "2026-11-20"
    },
    "F186": {
      "label": "Quickstart source file, bumble",
      "display": "device.py",
      "asOf": "2026-11-20"
    },
    "F187": {
      "label": "Repository stars, bumble",
      "display": "591",
      "asOf": "2026-11-20"
    },
    "F188": {
      "label": "Local GATT server, bumble",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F189": {
      "label": "Classic RFCOMM stack, bumble",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F190": {
      "label": "Bluetooth role and hardware boundary, bumble",
      "display": "Bluetooth stack with BLE and Classic protocol building blocks, explicit HCI transport, and device/GATT server construction.",
      "asOf": "2026-11-20"
    },
    "F191": {
      "label": "Project function, bumble",
      "display": "def make_pairing_config(security: int) -> PairingConfig:\n    \"\"\"Return a Bumble PairingConfig matching the given security setting.\"\"\"\n    # All modes use Secure Connections (sc=True) and bonding, matching the\n    # sm_set_secure_connections_only_mode(true) call in the Pico client.\n    common = dict(sc=True, bonding=True)\n    if security == 0:\n        # Just Works: no I/O capability, no MITM\n        return PairingConfig(mitm=False, delegate=PairingDelegate(\n            io_capability=PairingDelegate.IoCapability.NO_OUTPUT_NO_INPUT,\n        ), **common)\n    elif security == 1:\n        # Numeric Comparison: server displays, client confirms yes/no\n        return PairingConfig(mitm=True, delegate=PairingDelegate(\n            io_capability=PairingDelegate.IoCapability.DISPLAY_OUTPUT_AND_YES_NO_INPUT,\n        ), **common)\n    elif security == 2:\n        # Keyboard + Display: matches IO_CAPABILITY_KEYBOARD_DISPLAY on the Pico.\n        # Pairing method depends on the other side's capabilities.\n        return PairingConfig(mitm=True, delegate=KeyboardDelegate(\n            io_capability=PairingDelegate.IoCapability.DISPLAY_OUTPUT_AND_KEYBOARD_INPUT,\n        ), **common)\n    else:\n        # security == 3: Display Only - matches IO_CAPABILITY_DISPLAY_ONLY on the Pico.\n        # Requires the Pico client to be built with SECURITY_SETTING=2 (KEYBOARD_DISPLAY)\n        # so it can enter the passkey we display here.\n        return PairingConfig(mitm=True, delegate=DisplayDelegate(), **common)\n",
      "asOf": "2026-11-20"
    },
    "F192": {
      "label": "Project source file, bumble",
      "display": "bluetooth/ble_secure_temp_sensor/ble_temp_server.py",
      "asOf": "2026-11-20"
    },
    "F193": {
      "label": "Project full_name, bumble",
      "display": "raspberrypi/pico-examples",
      "asOf": "2026-11-20"
    },
    "F194": {
      "label": "Project stargazers_count, bumble",
      "display": "4.0K",
      "asOf": "2026-11-20"
    },
    "F195": {
      "label": "Library name, simplepyble",
      "display": "SimplePyBLE",
      "asOf": "2026-11-20"
    },
    "F196": {
      "label": "Monthly downloads, simplepyble",
      "display": "104.7K",
      "asOf": "2026-11-20"
    },
    "F197": {
      "label": "License, simplepyble",
      "display": "BUSL-1.1",
      "asOf": "2026-11-20"
    },
    "F198": {
      "label": "Package release, simplepyble",
      "display": "1.4.0",
      "asOf": "2026-11-20"
    },
    "F199": {
      "label": "Package release date, simplepyble",
      "display": "Nov 2026",
      "asOf": "2026-11-20"
    },
    "F200": {
      "label": "Install, simplepyble",
      "display": "python3.11 -m pip install simplepyble==1.4.0",
      "asOf": "2026-11-20"
    },
    "F201": {
      "label": "Quickstart, simplepyble",
      "display": "import simplepyble\n\nadapters = simplepyble.Adapter.get_adapters()\nif not adapters:\n    raise RuntimeError(\"No Bluetooth adapter found\")\nadapter = adapters[0]\nadapter.scan_for(1000)\nprint(adapter.scan_get_results())\n",
      "asOf": "2026-11-20"
    },
    "F202": {
      "label": "Official description, simplepyble",
      "display": "Binds the cross-platform SimpleBLE library for Windows, macOS, and Linux, with a license required for commercial use.",
      "asOf": "2026-11-20"
    },
    "F203": {
      "label": "Quickstart source file, simplepyble",
      "display": "wrap_adapter.cpp",
      "asOf": "2026-11-20"
    },
    "F204": {
      "label": "Repository stars, simplepyble",
      "display": "1.2K",
      "asOf": "2026-11-20"
    },
    "F205": {
      "label": "Local GATT server, simplepyble",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F206": {
      "label": "Classic RFCOMM stack, simplepyble",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F207": {
      "label": "Bluetooth role and hardware boundary, simplepyble",
      "display": "Cross-platform BLE bindings with synchronous and asyncio APIs plus local-peripheral/GATT-service APIs; current BUSL-1.1 non-commercial grant and separate commercial licensing.",
      "asOf": "2026-11-20"
    },
    "F208": {
      "label": "Project function, simplepyble",
      "display": "def connect(self, timeout=0):\n    \"\"\" Connect to the printer. Stops trying after <timeout> seconds. \"\"\"\n    if self.dummyPrinter:\n        return\n\n    self.peripheral = self.find_device(timeout=timeout)\n    if self.peripheral:\n        try:\n            self.log(f\"Connecting to {self.peripheral.identifier()} [{self.peripheral.address()}]\")\n            self.peripheral.connect()\n        except Exception as e:\n            if not self.quiet:\n                self.log(f'error on connecting: {e}')\n\n        if self.peripheral.is_connected():\n            # check if we're using a version of simplepyble that supports reading mtu\n            self.log(f\"Connected\")\n\n            # self.log('Attaching notification_handler')\n            try:\n                self.peripheral.notify(self.serviceUUID, self.notifyCharUUID, self.notification_handler)\n            except Exception as e:\n                if not self.quiet:\n                    self.log(f'Error on attaching notification_handler: {e}')\n                    return\n\n            self.get_printer_info()\n            sleep(1)\n            self.display_current_status()\n",
      "asOf": "2026-11-20"
    },
    "F209": {
      "label": "Project source file, simplepyble",
      "display": "InstaxBLE.py",
      "asOf": "2026-11-20"
    },
    "F210": {
      "label": "Project full_name, simplepyble",
      "display": "javl/InstaxBLE",
      "asOf": "2026-11-20"
    },
    "F211": {
      "label": "Project stargazers_count, simplepyble",
      "display": "121",
      "asOf": "2026-11-20"
    },
    "F212": {
      "label": "Library name, aioblescan",
      "display": "aioblescan",
      "asOf": "2026-11-20"
    },
    "F213": {
      "label": "Monthly downloads, aioblescan",
      "display": "89.9K",
      "asOf": "2026-11-20"
    },
    "F214": {
      "label": "License, aioblescan",
      "display": "MIT",
      "asOf": "2026-11-20"
    },
    "F215": {
      "label": "Package release, aioblescan",
      "display": "0.2.14",
      "asOf": "2026-11-20"
    },
    "F216": {
      "label": "Package release date, aioblescan",
      "display": "Jan 2023",
      "asOf": "2026-11-20"
    },
    "F217": {
      "label": "Install, aioblescan",
      "display": "python3.11 -m pip install aioblescan==0.2.14",
      "asOf": "2026-11-20"
    },
    "F218": {
      "label": "Quickstart, aioblescan",
      "display": "python3.11 -m aioblescan -D 0\n",
      "asOf": "2026-11-20"
    },
    "F219": {
      "label": "Official description, aioblescan",
      "display": "Scans for Bluetooth advertisements with asyncio.",
      "asOf": "2026-11-20"
    },
    "F220": {
      "label": "Quickstart source file, aioblescan",
      "display": "README.md",
      "asOf": "2026-11-20"
    },
    "F221": {
      "label": "Repository stars, aioblescan",
      "display": "127",
      "asOf": "2026-11-20"
    },
    "F222": {
      "label": "Local GATT server, aioblescan",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F223": {
      "label": "Classic RFCOMM stack, aioblescan",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F224": {
      "label": "Bluetooth role and hardware boundary, aioblescan",
      "display": "Linux raw HCI BLE advertising scan/packet decoding; sending advertising packets is different from a GATT server.",
      "asOf": "2026-11-20"
    },
    "F225": {
      "label": "Project function, aioblescan",
      "display": "def run(self):\n    \"\"\"Run HCIdump thread.\"\"\"\n    while True:\n        _LOGGER.debug(\"HCIdump thread: Run\")\n        mysocket = {}\n        fac = {}\n        conn = {}\n        btctrl = {}\n        interface_is_ok = {}\n        interfaces_to_reset = []\n        initialized_evt = {}\n        retry_handle = None\n        if self._event_loop is None:\n            self._event_loop = asyncio.new_event_loop()\n        asyncio.set_event_loop(self._event_loop)\n        if \"disable\" not in self.config[CONF_BT_INTERFACE]:\n            for hci in self._interfaces:\n                interface_is_ok[hci] = False\n                try:\n                    mysocket[hci] = aiobs.create_bt_socket(hci)\n                except OSError as error:\n                    _LOGGER.error(\"HCIdump thread: OS error (hci%i): %s\", hci, error)\n                else:\n                    fac[hci] = getattr(\n                        self._event_loop, \"_create_connection_transport\"\n                    )(mysocket[hci], aiobs.BLEScanRequester, None, None)\n                    conn[hci], btctrl[hci] = self._event_loop.run_until_complete(\n                        fac[hci]\n                    )\n                    # Wait up to five seconds for aioblescan BLEScanRequester to initialize\n                    initialized_evt[hci] = getattr(btctrl[hci], \"_initialized\")\n                    _LOGGER.debug(\n                        \"HCIdump thread: BLEScanRequester._initialized is %s for hci%i, \"\n                        \" waiting for connection...\",\n                        initialized_evt[hci].is_set(),\n                        hci,\n                    )\n                    try:\n                        self._event_loop.run_until_complete(asyncio.wait_for(initialized_evt[hci].wait(), 5))\n                    except asyncio.TimeoutError:\n                        _LOGGER.warn(\n                            \"HCIdump thread: Something wrong - interface hci%i not ready,\"\n                            \" and will be skipped for current scan period.\",\n                            hci,\n                        )\n                        conn[hci].close()\n                        fac[hci].close()\n                        mysocket[hci].close()\n                    else:\n                        btctrl[hci].process = partial(\n                            self.process_hci_events, hci=hci\n                        )\n                        _LOGGER.debug(\"HCIdump thread: connected to hci%i\", hci)\n                        try:\n                            self._event_loop.run_until_complete(\n                                btctrl[hci].send_scan_request(self._active)\n                            )\n                        except RuntimeError as error:\n                            _LOGGER.error(\n                                \"HCIdump thread: Runtime error while sending scan request on hci%i: %s.\",\n                                hci,\n                                error,\n                            )\n                            conn[hci].close()\n                            fac[hci].close()\n                            mysocket[hci].close()\n                        else:\n                            interface_is_ok[hci] = True\n                            self._record_hci_activity(hci)\n                            _LOGGER.debug(\n                                \"HCIdump thread: BLEScanRequester._initialized is %s for hci%i, \"\n                                \" connection established, send_scan_request succeeded.\",\n                                initialized_evt[hci].is_set(),\n                                hci,\n                            )\n                if interface_is_ok[hci] is False:\n                    self._last_hci_activity.pop(hci, None)\n                if (interface_is_ok[hci] is False) and (self.config[CONF_BT_AUTO_RESTART] is True):\n                    interfaces_to_reset.append(hci)\n            if interfaces_to_reset:\n                ts_now = time.monotonic()\n                if ts_now - self.last_bt_reset > 60:\n                    for iface in interfaces_to_reset:\n                        _LOGGER.error(\n                            \"HCIdump thread: Trying to power cycle Bluetooth adapter hci%i %s,\"\n                            \" will try to use it next scan period.\",\n                            iface,\n                            BT_INTERFACES[iface],\n                        )\n                        reset_bluetooth(iface)\n                    self.last_bt_reset = ts_now\n            if not all(interface_is_ok.values()):\n                retry_handle = self._schedule_scan_retry()\n        self._schedule_watchdog()\n        _LOGGER.debug(\"HCIdump thread: start main event_loop\")\n        try:\n            self._event_loop.run_forever()\n        finally:\n            _LOGGER.debug(\"HCIdump thread: main event_loop stopped, finishing.\")\n            if self._watchdog_handle is not None:\n                self._watchdog_handle.cancel()\n                self._watchdog_handle = None\n            if retry_handle is not None:\n                retry_handle.cancel()\n            if \"disable\" not in self.config[CONF_BT_INTERFACE]:\n                for hci in self._interfaces:\n                    if interface_is_ok[hci] is True:\n                        try:\n                            self._event_loop.run_until_complete(\n                                btctrl[hci].stop_scan_request()\n                            )\n                        except RuntimeError as error:\n                            _LOGGER.error(\n                                \"HCIdump thread: Runtime error while stop scan request on hci%i: %s.\",\n                                hci,\n                                error,\n                            )\n                        except KeyError:\n                            _LOGGER.debug(\n                                \"HCIdump thread: Key error while stop scan request on hci%i\",\n                                hci,\n                            )\n                    try:\n                        conn[hci].close()\n                        fac[hci].close()\n                        mysocket[hci].close()\n                    except KeyError:\n                        _LOGGER.debug(\n                            \"HCIdump thread: Key error while closing connection on hci%i\",\n                            hci,\n                        )\n                    self._last_hci_activity.pop(hci, None)\n            self._event_loop.run_until_complete(asyncio.sleep(0))\n        if self._joining is True:\n            break\n        _LOGGER.debug(\"HCIdump thread: Scanning will be restarted\")\n        _LOGGER.debug(\n            \"HCI events processed for previous scan: %s\", self.evt_cnt\n        )\n        self.evt_cnt = {}\n    self._event_loop.close()\n    _LOGGER.debug(\"HCIdump thread: Run finished\")",
      "asOf": "2026-11-20"
    },
    "F226": {
      "label": "Project source file, aioblescan",
      "display": "custom_components/ble_monitor/__init__.py",
      "asOf": "2026-11-20"
    },
    "F227": {
      "label": "Project full_name, aioblescan",
      "display": "custom-components/ble_monitor",
      "asOf": "2026-11-20"
    },
    "F228": {
      "label": "Project stargazers_count, aioblescan",
      "display": "2.3K",
      "asOf": "2026-11-20"
    },
    "F229": {
      "label": "Library name, bleak-esphome",
      "display": "bleak-esphome",
      "asOf": "2026-11-20"
    },
    "F230": {
      "label": "Monthly downloads, bleak-esphome",
      "display": "65.5K",
      "asOf": "2026-11-20"
    },
    "F231": {
      "label": "License, bleak-esphome",
      "display": "MIT",
      "asOf": "2026-11-20"
    },
    "F232": {
      "label": "Package release, bleak-esphome",
      "display": "4.1.0",
      "asOf": "2026-11-20"
    },
    "F233": {
      "label": "Package release date, bleak-esphome",
      "display": "Aug 2026",
      "asOf": "2026-11-20"
    },
    "F234": {
      "label": "Install, bleak-esphome",
      "display": "python3.11 -m pip install bleak-esphome==4.1.0 bleak==3.1.0 habluetooth==7.1.3",
      "asOf": "2026-11-20"
    },
    "F235": {
      "label": "Quickstart, bleak-esphome",
      "display": "import asyncio, os\nfrom habluetooth import BluetoothManager\nfrom bleak import BleakScanner\nfrom bleak_esphome import APIConnectionManager\n\nasync def main():\n    manager = BluetoothManager()\n    await manager.async_setup()\n    connection = APIConnectionManager({\"address\": os.environ[\"ESPHOME_HOST\"], \"noise_psk\": os.getenv(\"ESPHOME_NOISE_PSK\")})\n    try:\n        await connection.start()\n        print(await BleakScanner.discover())\n    finally:\n        await connection.stop()\n        manager.async_stop()\n\nasyncio.run(main())\n",
      "asOf": "2026-11-20"
    },
    "F236": {
      "label": "Official description, bleak-esphome",
      "display": "Provides the ESPHome backend for Bleak.",
      "asOf": "2026-11-20"
    },
    "F237": {
      "label": "Quickstart source file, bleak-esphome",
      "display": "usage.html",
      "asOf": "2026-11-20"
    },
    "F238": {
      "label": "Repository stars, bleak-esphome",
      "display": "14",
      "asOf": "2026-11-20"
    },
    "F239": {
      "label": "Local GATT server, bleak-esphome",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F240": {
      "label": "Classic RFCOMM stack, bleak-esphome",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F241": {
      "label": "Bluetooth role and hardware boundary, bleak-esphome",
      "display": "Standalone ESP32 ESPHome remote Bluetooth proxy host lifecycle and routing into Bleak; remote firmware feature flags determine operations.",
      "asOf": "2026-11-20"
    },
    "F242": {
      "label": "Project function, bleak-esphome",
      "display": "@hass_callback\ndef async_connect_scanner(\n    hass: HomeAssistant,\n    entry: ESPHomeConfigEntry,\n    entry_data: RuntimeEntryData,\n    cli: APIClient,\n    device_info: DeviceInfo,\n    device_id: str,\n) -> CALLBACK_TYPE:\n    \"\"\"Connect scanner.\"\"\"\n    client_data = connect_scanner(cli, device_info, entry_data.available)\n    entry_data.bluetooth_device = client_data.bluetooth_device\n    client_data.disconnect_callbacks = entry_data.disconnect_callbacks\n    scanner = client_data.scanner\n    if TYPE_CHECKING:\n        assert scanner is not None\n    api_version = cli.api_version or APIVersion()\n    feature_flags = device_info.bluetooth_proxy_feature_flags_compat(api_version)\n    state_and_mode = bool(feature_flags & BluetoothProxyFeature.FEATURE_STATE_AND_MODE)\n    # Pin mode before async_register_scanner so habluetooth spawns the AUTO worker.\n    deferred_migration: CALLBACK_TYPE | None = None\n    if state_and_mode:\n        deferred_migration = _async_apply_scanning_mode(hass, entry, scanner, cli)\n    callbacks: list[CALLBACK_TYPE] = [\n        async_register_scanner(\n            hass,\n            scanner,\n            source_domain=DOMAIN,\n            source_model=device_info.model,\n            source_config_entry_id=entry_data.entry_id,\n            source_device_id=device_id,\n        ),\n        scanner.async_setup(),\n    ]\n    if deferred_migration is not None:\n        callbacks.append(deferred_migration)\n    return partial(_async_unload, callbacks)",
      "asOf": "2026-11-20"
    },
    "F243": {
      "label": "Project source file, bleak-esphome",
      "display": "homeassistant/components/esphome/bluetooth.py",
      "asOf": "2026-11-20"
    },
    "F244": {
      "label": "Project full_name, bleak-esphome",
      "display": "home-assistant/core",
      "asOf": "2026-11-20"
    },
    "F245": {
      "label": "Project stargazers_count, bleak-esphome",
      "display": "92.3K",
      "asOf": "2026-11-20"
    },
    "F246": {
      "label": "Library name, bless",
      "display": "Bless",
      "asOf": "2026-11-20"
    },
    "F247": {
      "label": "Monthly downloads, bless",
      "display": "33.5K",
      "asOf": "2026-11-20"
    },
    "F248": {
      "label": "License, bless",
      "display": "MIT",
      "asOf": "2026-11-20"
    },
    "F249": {
      "label": "Package release, bless",
      "display": "0.3.0",
      "asOf": "2026-11-20"
    },
    "F250": {
      "label": "Package release date, bless",
      "display": "Dec 2025",
      "asOf": "2026-11-20"
    },
    "F251": {
      "label": "Install, bless",
      "display": "python3.11 -m pip install bless==0.3.0",
      "asOf": "2026-11-20"
    },
    "F252": {
      "label": "Quickstart, bless",
      "display": "import asyncio\nfrom bless import BlessServer, GATTCharacteristicProperties, GATTAttributePermissions\n\nasync def main():\n    server = BlessServer(name=\"BLE example\")\n    service = \"0000180f-0000-1000-8000-00805f9b34fb\"\n    characteristic = \"00002a19-0000-1000-8000-00805f9b34fb\"\n    await server.add_new_service(service)\n    await server.add_new_characteristic(service, characteristic, GATTCharacteristicProperties.read, bytearray([100]), GATTAttributePermissions.readable)\n    server.read_request_func = lambda item, **kwargs: item.value\n    await server.start()\n    try:\n        await asyncio.sleep(5)\n    finally:\n        await server.stop()\n\nasyncio.run(main())\n",
      "asOf": "2026-11-20"
    },
    "F253": {
      "label": "Repository stars, bless",
      "display": "197",
      "asOf": "2026-11-20"
    },
    "F254": {
      "label": "Local GATT server, bless",
      "display": "Yes",
      "asOf": "2026-11-20"
    },
    "F255": {
      "label": "Classic RFCOMM stack, bless",
      "display": "No",
      "asOf": "2026-11-20"
    },
    "F256": {
      "label": "Bluetooth role and hardware boundary, bless",
      "display": "BLE peripheral/GATT server implementing local services/characteristics for clients to read/write or subscribe.",
      "asOf": "2026-11-20"
    },
    "F257": {
      "label": "Project function, bless",
      "display": "async def setup_chars(self, service_uuid: str, write_uuid: str, read_uuid: str, mode: str, write_response_required: bool):\n    self.read_enabled = 'r' in mode\n    self.write_enabled = 'w' in mode\n\n    self.service_uuid = service_uuid\n    self.write_uuid = check_fill_empty(service_uuid, write_uuid, 'write')\n    self.read_uuid = check_fill_empty(service_uuid, read_uuid, 'read')\n\n    await self.server.add_new_service(self.service_uuid)\n    self.service = self.server.get_service(self.service_uuid)\n    logging.info(f'Service {self.service_uuid}')\n\n    if self.write_enabled:\n        # self.write_uuid = \"0000ffe1-0000-1000-8000-00805f9b34fb\"\n        char_flags = (\n            GATTCharacteristicProperties.write if write_response_required else\n            GATTCharacteristicProperties.write_without_response)\n        permissions = GATTAttributePermissions.readable | GATTAttributePermissions.writeable\n        await self.server.add_new_characteristic(self.service_uuid, self.write_uuid,\n            char_flags, None, permissions)\n\n        self.write_char = self.server.get_characteristic(self.write_uuid)\n        logging.info(f'Write characteristic: {str(self.write_char)}')\n    else:\n        logging.info('Writing disabled, no characteristic to setup')\n\n    if self.read_enabled:\n        char_flags = GATTCharacteristicProperties.read | GATTCharacteristicProperties.notify\n        permissions = GATTAttributePermissions.readable | GATTAttributePermissions.writeable\n        await self.server.add_new_characteristic(self.service_uuid, self.read_uuid,\n            char_flags, None, permissions)\n\n        self.read_char = self.server.get_characteristic(self.read_uuid)\n        logging.info(f'Read characteristic: {str(self.read_char)}')\n\n        self.data_read_done.set()\n    else:\n        logging.info('Reading disabled, no characteristic to setup')\n",
      "asOf": "2026-11-20"
    },
    "F258": {
      "label": "Project source file, bless",
      "display": "ble_serial/bluetooth/ble_server.py",
      "asOf": "2026-11-20"
    },
    "F259": {
      "label": "Project full_name, bless",
      "display": "Jakeler/ble-serial",
      "asOf": "2026-11-20"
    },
    "F260": {
      "label": "Project stargazers_count, bless",
      "display": "390",
      "asOf": "2026-11-20"
    }
  },
  "dataCheckedAt": "2026-11-20",
  "agent": {
    "exaCall": {
      "endpoint": "/search",
      "body": {
        "query": "Best Python Bluetooth libraries Bleak bluepy PyBluez Bless code examples",
        "numResults": 5
      },
      "docsUrl": "https://exa.ai/docs/reference/search"
    },
    "calls": []
  }
}
