Add Homebridge Matter Support for Homebridge v2.0#41
Conversation
Agent-Logs-Url: https://github.com/homebridge-plugins/homebridge-meater/sessions/9c214ee5-2409-411d-ac4f-a8ffb518c0df Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
Agent-Logs-Url: https://github.com/homebridge-plugins/homebridge-meater/sessions/9c214ee5-2409-411d-ac4f-a8ffb518c0df Co-authored-by: donavanbecker <9875439+donavanbecker@users.noreply.github.com>
There was a problem hiding this comment.
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
MeaterMatterPlatformextendingMeaterPlatformfor 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. |
| export function normalizeConfig(raw?: PlatformConfig): MeaterPlatformConfig { | ||
| if (!raw) { | ||
| return {} as MeaterPlatformConfig | ||
| } | ||
| return { ...(raw as any) } as MeaterPlatformConfig | ||
| } |
| 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() |
|
@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>
Addressed in d326a1a:
|
Pull Request
Description
Adds Homebridge Matter support with HAP fallback, following the patterns established by
homebridge-switchbotandhomebridge-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.ts—normalizeConfig()+createPlatformProxy(HAPPlatform, MatterPlatform)factory.normalizeConfig()returnsundefinedfor falsy input (preservingMeaterPlatform'sif (!config) returnguard). The proxy checksapi.isMatterAvailable?.()/api.isMatterEnabled?.()at instantiation time and routes accordingly, short-circuiting on falsy config before reading options.src/MeaterMatterPlatform.ts— ExtendsMeaterPlatform, inheriting all device discovery/management logic includingconfigureAccessory(not overridden, so cached HAP accessories are correctly restored intothis.accessories). OverridesexternalOrPlatform()to log the Matter-aware path (Homebridge handles Matter bridging internally viaregisterPlatformAccessories).Modified files:
src/settings.ts— AddedpreferMatter?: booleanandenableMatter?: booleanto theoptionsinterface.src/index.ts— Registers via proxy instead of directly registeringMeaterPlatform.config.schema.json— AddedpreferMatter/enableMatterschema 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.Related Issue
Type of Change
Branch Targeting
beta-{version}branch (required by Copilot instructions)Testing
Checklist
Notes for Reviewers
MeaterMatterPlatform.externalOrPlatformcurrently mirrors HAP behavior — the differentiation point is the proxy selection logic. When Homebridge v2.0 exposes a dedicated Matter registration API (beyondregisterPlatformAccessories), onlyMeaterMatterPlatformneeds updating.MeaterMatterPlatformintentionally does not overrideconfigureAccessory, ensuring cached HAP accessories are correctly tracked inthis.accessorieson 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.