Skip to content

Add Laifen integration - #194907

Open
bzumik1 wants to merge 7 commits into
home-assistant:devfrom
bzumik1:add-laifen
Open

bzumik1 wants to merge 7 commits into
home-assistant:devfrom
bzumik1:add-laifen

Conversation

@bzumik1

@bzumik1 bzumik1 commented Nov 26, 2026 •

Copy link
Copy Markdown

Proposed change

This adds the Laifen integration for the Laifen Wave (LFTB01-P) electric toothbrush, which is reached over Bluetooth LE.

The toothbrush is a sleepy device. It only advertises while it is awake (after a button press, or while it sits on its charger), and its advertisements never change. The integration connects when it advertises and keeps the connection while the toothbrush is awake. It clears the advertisement history at setup and after every disconnect, as async_clear_advertisement_history describes, so the next identical wake-up is heard. The toothbrush pushes its state over the connection, but not battery changes, so the state is read every minute while it stays connected on its charger.

This first PR adds the config flow (Bluetooth discovery and a user step, both test the connection) and the sensor platform: battery, current brushing duration and last brushing duration. The current brushing duration is updated every second while the toothbrush brushes. The battery and last brushing duration sensors keep their last value while the toothbrush sleeps. The event, select, number and switch platforms and diagnostics will follow in separate PRs.

The communication is in the laifen-ble library (MIT), published from GitHub Actions with trusted publishing: release workflow, tag 0.4.1. Its protocol is based on marc-alexis-com/laifen-toolbox. I tested the integration on a real LFTB01-P with firmware V2.0.93, through ESPHome Bluetooth proxies and the local adapter.

Why core: Laifen Wave owners already use Home Assistant through the UrbanTechIO/Laifen custom integration (25 stars, 10 issues and 5 pull requests since January 2025). I contacted its author about a core integration in UrbanTechIO/Laifen#15, but there is no reply yet. I run this integration as a custom integration on my own Home Assistant since 26 November 2026, and the protocol is documented independently in laifen-toolbox. In core, Laifen Wave owners get Bluetooth discovery and a maintained integration without installing a custom one.

Brand images: home-assistant/brands#11474

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests (refactoring, typing, performance, etc.)
  • Developer tooling (CI, GitHub workflows, linters and checkers, scripts, AI instructions, code owners)

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI adaptive review requested due to automatic review settings November 26, 2026 23:01
@home-assistant

home-assistant Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

👋 Hi! Thanks for contributing to Home Assistant.

This is your PR dashboard which flags anything you need to address before your PR can be reviewed. Once everything is green, you can press the 'Ready for review' button at the bottom of the page to notify reviewers to take a look.

More information about this dashboard

This dashboard automatically updates on every change to this PR and reevaluates the rules as you go. Until everything has been addressed, the bot will keep the PR in draft.

Skip a check that doesn't apply

If you think a check doesn't apply to your PR (or the rule is bugged), comment @home-assistant ignore "<check name>" "<reason>". The check name as shown in the table above. This will mark the check as ignored and let you put your PR in 'Ready for review'; @home-assistant unignore "<check name>" restores the rule.

Bot commands

Reply with @home-assistant <command>. Several commands can be stacked, one per line:

  • update — Re-runs the bot's checks on the issue or pull request.
  • ignore — Waives a dashboard check: ignore "<check name>" "<reason>". (author) — e.g. @home-assistant ignore "Merge conflicts" "Broken rule, no merge conflicts present"
  • unignore — Restores a waived dashboard check: unignore "<check name>". (author) — e.g. @home-assistant unignore "Merge conflicts"
  • unassign — Removes the given integration domain's label and its code owners from the assignees. (author or code owners) — e.g. @home-assistant unassign "opensky"
  • close — Closes the issue or pull request. (code owners)
  • reopen — Reopens the issue or pull request. (code owners)
  • rename — Renames the issue or pull request: rename "<new title>". (code owners) — e.g. @home-assistant rename "A more descriptive title"
  • add-label — Adds a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the issue or pull request. (code owners) — e.g. @home-assistant add-label "needs-more-information"
  • remove-label — Removes a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) from the issue or pull request. (code owners) — e.g. @home-assistant remove-label "needs-more-information"
  • mark-draft — Marks the pull request as draft. (code owners)
  • update-branch — Updates the pull request branch with the base branch. (code owners)

Checks

✨ Everything's in order!

8 checks passed (3 skipped)
Status Check Details
✅ New integration validation Validation passed.
✅ Forbidden files No forbidden files.
✅ Documentation Documentation PR linked
✅ Belongs together Belongs together with home-assistant/brands#11474, home-assistant/home-assistant.io#51241.
✅ Merge conflicts Merge status is being recalculated by GitHub.
✅ Merge target This PR targets dev.
✅ Type of change Type of change: new-integration
✅ CLA Everyone involved has signed the CLA.
➖ Single new platform New-integration PRs are checked by new integration validation.
➖ Code owner approval Touches no platinum integration — no code-owner approval required.
➖ Blocking: awaiting-frontend awaiting-frontend label not set — nothing to block.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

After a polling failure, valid toothbrush push updates leave last_update_success false, keeping both sensors unavailable; the recovery path needs a fix and regression test.

1 open issue
What changed in this PR

Adds Bluetooth LE support for the Laifen Wave toothbrush (LFTB01-P), with discovery, connection validation, and sensors that retain their last values while the device sleeps.

Changes:

  • Adds Bluetooth discovery and user setup flows.
  • Manages wake-up connections, pushed updates, and periodic battery reads.
  • Adds battery and brushing-duration sensors, tests, and integration registration.
File Description
tests/​components/​laifen/​test_sensor.py Tests sensor updates, restoration, and availability.
tests/​components/​laifen/​test_init.py Tests connection lifecycle, polling, and shutdown.
tests/​components/​laifen/​test_config_flow.py Tests discovery and user setup flows.
tests/​components/​laifen/​snapshots/​test_sensor.ambr Captures sensor state and registry snapshots.
tests/​components/​laifen/​conftest.py Provides shared toothbrush mocks and fixtures.
tests/​components/​laifen/​__init__.py Adds setup and advertisement test helpers.
requirements_all.txt Pins the laifen-ble dependency.
mypy.ini Enables strict typing checks for Laifen.
homeassistant/​generated/​integrations.json Registers integration metadata.
homeassistant/​generated/​config_flows.py Registers the configuration flow.
homeassistant/​generated/​bluetooth.py Adds the Bluetooth discovery matcher.
homeassistant/​components/​laifen/​strings.json Defines setup messages and sensor translations.
homeassistant/​components/​laifen/​sensor.py Implements battery and brushing-duration sensors.
homeassistant/​components/​laifen/​quality_scale.yaml Records quality-scale implementation status.
homeassistant/​components/​laifen/​manifest.json Declares metadata, discovery, and dependencies.
homeassistant/​components/​laifen/​icons.json Defines the brushing-duration icon.
homeassistant/​components/​laifen/​entity.py Provides shared entity identity and device linkage.
homeassistant/​components/​laifen/​coordinator.py Handles connections, notifications, and polling.
homeassistant/​components/​laifen/​const.py Defines the integration domain.
homeassistant/​components/​laifen/​config_flow.py Implements discovery and user configuration.
homeassistant/​components/​laifen/​__init__.py Sets up devices, sensors, and lifecycle cleanup.
CODEOWNERS Assigns integration and test ownership.
.strict-typing Includes Laifen in strict typing coverage.

Review effort: Balanced (adaptive)

Notify the listeners with async_set_updated_data, so a pushed state
marks the update as successful again after an unexpected error.
Copilot AI adaptive review requested due to automatic review settings November 26, 2026 23:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Tests mock laifen-ble’s cleanup and callback contracts, leaving the unavailable pinned implementation’s failure handling, reconnect behavior, and BLE proxy lifecycle unverified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced (adaptive)

Copilot AI adaptive review requested due to automatic review settings November 26, 2026 23:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The sleepy-device lifecycle needs human validation because laifen-ble 0.3.10 callback and connection-cleanup guarantees could not be verified without its source or a device/proxy runtime.

No open issues 🎉

Review effort: Balanced (adaptive)

Copilot AI adaptive review requested due to automatic review settings November 27, 2026 08:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The unavailable laifen-ble 0.4.0 implementation leaves connection, notification, and cleanup contracts unverified, and mocked tests cannot establish the required hardware lifecycle guarantees.

No open issues 🎉

Review effort: Balanced (adaptive)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

BLE cleanup and reconnect guarantees depend on unavailable laifen-ble source and unverified hardware behavior, while documentation, assets, coverage, and quality-scale checks also require verification.

No open issues 🎉

Review effort: Balanced (adaptive)

@github-actions

Copy link
Copy Markdown
Contributor

Check requirements

Checked at commit e371322.

All requirements checks passed. ✅

Package Old New No Advisories Not Yanked Repo Public CI Upload Release Pipeline Security PR Link Async Safe
laifen-ble — 0.4.0 ✅ ✅ ✅ ✅ ✅ ☑️ ✅ ✅
📦 laifen-ble: 0.4.0
  • No Advisories: ✅ No active advisories reported by PyPI for version 0.4.0.
  • Not Yanked: ✅ Version 0.4.0 is a live (non-yanked) release.
  • Repo Public: ✅ https://github.com/bzumik1/laifen-ble is publicly accessible.
  • CI Upload: ✅ Trusted Publisher attestation found (GitHub).
  • Release Pipeline: ✅ OIDC via Trusted Publisher attestation (GitHub); automated CI upload verified by PyPI.
  • Security: ☑️ Baseline scan found nothing obvious in README.md, pyproject.toml, and src/laifen_ble/{init,const,device,exceptions,models,protocol}.py. This is not a security review — only the cheap checks were run.
  • PR Link: ✅ PR description links to the source repository at https://github.com/bzumik1/laifen-ble.
  • Async Safe: ✅ No blocking calls found across the 0.4.0 async surface.

Generated by Check requirements (AW) · copilot · routed: gpt56 max · ~65 AIC · ⌖ ~16 AIC · ⊞ 538 · history

Copilot AI adaptive review requested due to automatic review settings November 27, 2026 12:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The persistent BLE lifecycle relies on unverified laifen-ble 0.4.1 callback, session-reset, and cleanup contracts that require upstream-source or device-level review.

No open issues 🎉

Review effort: Balanced (adaptive)

@github-actions

Copy link
Copy Markdown
Contributor

Check requirements

Checked at commit 91feb38.

⚠️ Some checks require attention — see the details below.

Package Old New No Advisories Not Yanked Repo Public CI Upload Release Pipeline Security PR Link Async Safe
laifen-ble — 0.4.1 ✅ ✅ ⚠️ ✅ ✅ ☑️ ✅ ✅
📦 laifen-ble: 0.4.1
  • No Advisories: ✅ No active advisories reported by PyPI for version 0.4.1.
  • Not Yanked: ✅ Version 0.4.1 is a live (non-yanked) release.
  • Repo Public: ⚠️ Web fetch of https://github.com/bzumik1/laifen-ble failed; GitHub API metadata identifies the repository as public, but direct public-page access could not be verified.
  • CI Upload: ✅ Trusted Publisher attestation found (GitHub).
  • Release Pipeline: ✅ OIDC via Trusted Publisher attestation (GitHub); automated CI upload verified by PyPI.
  • Security: ☑️ Baseline scan found nothing obvious in pyproject.toml, src/laifen_ble/__init__.py, src/laifen_ble/const.py, src/laifen_ble/device.py, src/laifen_ble/exceptions.py, src/laifen_ble/models.py, and src/laifen_ble/protocol.py. This is not a security review — only the cheap checks were run.
  • PR Link: ✅ The PR description links to the source repository at https://github.com/bzumik1/laifen-ble.
  • Async Safe: ✅ No blocking calls found in async methods or reachable helpers across all six package modules at aab8d3f, the commit shared by tag 0.4.1 and the inspected default-branch files; Bluetooth I/O is awaited.

Generated by Check requirements (AW) · copilot · routed: gpt60 max · ~170 AIC · ⌖ ~13 AIC · ⊞ 538 · history

@bzumik1
bzumik1 marked this pull request as ready for review November 30, 2026 20:09

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants