import type { Characteristic, HapStatusError, PlatformAccessory, Service } from 'homebridge'; import type { PhilipsTVClient } from '../api/PhilipsTVClient.js'; export interface SourceSwitchDeps { readonly Service: typeof Service; readonly Characteristic: typeof Characteristic; readonly tvClient: PhilipsTVClient; /** Homebridge storage path for persisting user switch renames. */ readonly storagePath: string; /** Device id (MAC) used to key the persisted rename file. */ readonly deviceId: string; readonly communicationError: () => HapStatusError; readonly log: (level: 'debug' | 'info' | 'warn' | 'error', message: string) => void; readonly onSourceSwitch?: (sourceId: string) => void; } /** * Exposes input sources as individual Switch services in HomeKit. * This allows sources to be used in HomeKit automations and scenes, * which is not possible with the standard Television InputSource services. * * Only one switch is ON at a time (the currently active source). * Turning a switch ON launches that source on the TV. */ export declare class SourceSwitchService { private readonly deps; private switches; private activeSourceId; /** User-set switch names, keyed by source id. Persisted to disk because the * TV accessory is external and its context is not saved across restarts. */ private customNames; private readonly namesCachePath; constructor(deps: SourceSwitchDeps); private loadCustomNames; private saveCustomNames; configureSwitches(accessory: PlatformAccessory, sources: ReadonlyArray<{ id: string; name: string; type: 'app' | 'source' | 'channel'; channelListId?: string; className?: string; action?: string; }>, tvName: string): void; /** * Decide what to write to a switch's ConfiguredName, without clobbering a * rename the user made in the Home app. * * The Home app frequently keeps a switch rename *client-side* and never writes * it back to ConfiguredName, so we can't capture it. Re-asserting our default * name on every restart (the old behaviour) then reset the user's rename. So: * - a rename we *did* capture (customNames) always wins and is restored; * - a brand-new switch is seeded with the source's default/label; * - an existing switch is left untouched, except to upgrade a leftover * package-id placeholder (e.g. "com netflix ninja") to the real label once * the TV reports it. */ private applyConfiguredName; /** Persist a switch name the user changed in HomeKit so it survives restarts. */ private handleRenameSwitch; private handleGetSwitch; private handleSetSwitch; /** * Update switch states from poll data (current active app/source). * Called by the accessory when the active input changes. * * Only updates if the polled source matches a known switch. * The TV may report system package names (e.g. org.droidtv.playtv) that * don't match the URI-based IDs used by Watch TV / Home sources — in that * case we keep the current state so switches don't bounce off. */ updateFromPoll(currentSourceId: string | null): void; /** Turn off all switches (e.g., when TV powers off) */ resetAll(): void; private setActiveSource; private launchSource; }