Skip to content

Add Homebridge Matter Support for Homebridge v2.0#41

Open
Copilot wants to merge 4 commits intolatestfrom
copilot/add-homebridge-matter-support
Open

Add Homebridge Matter Support for Homebridge v2.0#41
Copilot wants to merge 4 commits intolatestfrom
copilot/add-homebridge-matter-support

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 14, 2026

Pull Request

Description

Adds Homebridge Matter support with HAP fallback, following the patterns established by homebridge-switchbot and homebridge-matter. A runtime proxy selects Matter or HAP platform based on Homebridge v2.0 API availability and user config — zero behavior change on Homebridge v1.x.

New files:

  • src/utils.tsnormalizeConfig() + createPlatformProxy(HAPPlatform, MatterPlatform) factory. normalizeConfig() returns undefined for falsy input (preserving MeaterPlatform's if (!config) return guard). The proxy checks api.isMatterAvailable?.() / api.isMatterEnabled?.() at instantiation time and routes accordingly, short-circuiting on falsy config before reading options.
  • src/MeaterMatterPlatform.ts — Extends MeaterPlatform, inheriting all device discovery/management logic including configureAccessory (not overridden, so cached HAP accessories are correctly restored into this.accessories). Overrides externalOrPlatform() to log the Matter-aware path (Homebridge handles Matter bridging internally via registerPlatformAccessories).

Modified files:

  • src/settings.ts — Added preferMatter?: boolean and enableMatter?: boolean to the options interface.
  • src/index.ts — Registers via proxy instead of directly registering MeaterPlatform.
  • config.schema.json — Added preferMatter/enableMatter schema fields and a "Matter Settings (Homebridge v2.0+)" layout fieldset.
  • src/index.test.ts — Updated to assert proxy-based registration; added tests for Matter platform selection, config-flag gating (preferMatter/enableMatter), HAP fallback paths, and falsy-config guard.
// src/index.ts — before
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, MeaterPlatform)

// src/index.ts — after
const ProxyCtor = createPlatformProxy(MeaterPlatform, MeaterMatterPlatform)
api.registerPlatform(PLUGIN_NAME, PLATFORM_NAME, ProxyCtor as any)

Related Issue

Type of Change

  • 🐛 Bug fix (patch) - non-breaking change that fixes an issue
  • ✨ New feature (minor) - non-breaking change that adds functionality
  • 💥 Breaking change (major) - change that would cause existing functionality to not work as expected
  • 📚 Documentation update
  • 🧹 Code cleanup/refactoring

Branch Targeting

  • This PR targets a beta-{version} branch (required by Copilot instructions)
  • The target version matches the semantic versioning label on the related issue
  • package.json version has been updated to match the target version

Testing

  • I have tested these changes locally
  • All existing tests pass
  • New tests have been added (if applicable)

Checklist

  • Code follows the project's coding standards
  • Self-review of the code has been performed
  • Code is well-commented, particularly in hard-to-understand areas
  • Documentation has been updated (if applicable)

Notes for Reviewers

MeaterMatterPlatform.externalOrPlatform currently mirrors HAP behavior — the differentiation point is the proxy selection logic. When Homebridge v2.0 exposes a dedicated Matter registration API (beyond registerPlatformAccessories), only MeaterMatterPlatform needs updating.

MeaterMatterPlatform intentionally does not override configureAccessory, ensuring cached HAP accessories are correctly tracked in this.accessories on restore and that the HAP fallback path within the platform operates without creating duplicate accessories.


This PR was created following the GitHub Copilot Instructions for proper branch targeting and semantic versioning.

Copilot AI and others added 2 commits April 14, 2026 04:04
Copilot AI changed the title [WIP] Add Homebridge Matter support with HAP fallback Add Homebridge Matter Support for Homebridge v2.0 Apr 14, 2026
Copilot AI requested a review from donavanbecker April 14, 2026 04:09
@donavanbecker donavanbecker marked this pull request as ready for review April 14, 2026 04:13
Copilot AI review requested due to automatic review settings April 14, 2026 04:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds runtime-selectable Homebridge Matter support (Homebridge v2.0+) with a HAP fallback by introducing a platform proxy that chooses between the existing HAP platform and a new Matter-aware platform implementation.

Changes:

  • Added createPlatformProxy() + normalizeConfig() utilities to select Matter vs HAP at runtime.
  • Introduced MeaterMatterPlatform extending MeaterPlatform for Matter-mode initialization/registration.
  • Extended config/types/schema and updated registration tests for proxy-based platform registration.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/utils.ts Adds config normalization + runtime proxy factory to select Matter/HAP platform.
src/MeaterMatterPlatform.ts New Matter platform class extending existing platform logic.
src/settings.ts Adds Matter-related options (preferMatter, enableMatter) to typed config.
src/index.ts Switches platform registration to use proxy constructor.
src/index.test.ts Updates tests to assert proxy registration + basic HAP fallback instantiation.
config.schema.json Adds UI/schema fields for Matter settings.
package-lock.json Formatting-only change.

Comment thread src/utils.ts Outdated
Comment on lines +15 to +20
export function normalizeConfig(raw?: PlatformConfig): MeaterPlatformConfig {
if (!raw) {
return {} as MeaterPlatformConfig
}
return { ...(raw as any) } as MeaterPlatformConfig
}
Comment thread src/index.test.ts Outdated
Comment on lines +19 to +34
it('should register a proxy that falls back to HAP when Matter is unavailable', () => {
const api = {
registerPlatform: vi.fn(),
} as unknown as API

registerPlatform(api)

const [, , ProxyCtor] = (api.registerPlatform as ReturnType<typeof vi.fn>).mock.calls[0]

// Instantiate the proxy without Matter available — should use HAP platform.
const log = { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn(), success: vi.fn() }
const config = { platform: 'Meater', options: {} }
const mockApi = { hap: { uuid: { generate: vi.fn(() => 'uuid') } }, on: vi.fn(), registerPlatform: vi.fn() }

// Should not throw when instantiated in HAP fallback mode.
expect(() => new ProxyCtor(log, config, mockApi)).not.toThrow()
@donavanbecker
Copy link
Copy Markdown
Collaborator

@copilot apply changes based on the comments in this thread

Also make sure this isn't happening: configureAccessory is overridden as a no-op, which leaves any previously cached HAP accessories registered (and untracked) when switching to Matter. It also breaks the super.discoverDevices() fallback path (because the HAP cache won’t be populated), leading to duplicate HAP accessories being created. Consider either unregistering HAP accessories as they are restored, or delegating to super.configureAccessory(accessory) when you intend to support HAP fallback within this class.

…Accessory inheritance

Agent-Logs-Url: https://github.com/homebridge-plugins/homebridge-meater/sessions/87de084c-a642-4133-a322-54460dca81ff

Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 14, 2026

@copilot apply changes based on the comments in this thread

Also make sure this isn't happening: conf...

Addressed in d326a1a:

  1. normalizeConfig() falsy-config bug — now returns undefined instead of {} for falsy input, preserving MeaterPlatform's if (!config) return early-exit guard. The proxy HAP fallback path passes the original config reference unchanged.

  2. configureAccessory no-opMeaterMatterPlatform does not override configureAccessory; it inherits super.configureAccessory() from MeaterPlatform, which correctly populates this.accessories on cache restore. No change was needed here.

  3. Matter selection tests — added tests for: Matter platform chosen when isMatterAvailable/isMatterEnabled return true; HAP fallback when preferMatter: false; HAP fallback when enableMatter: false; and the falsy-config guard.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Homebridge Matter Support for Homebridge v2.0

3 participants