homebridge-kasa-python
Version:
Plugin that uses Python-Kasa API to communicate with Kasa Devices.
67 lines (66 loc) • 4.03 kB
TypeScript
import type { Categories, Characteristic, CharacteristicValue, HapStatusError, Logger, Nullable, PlatformAccessory, Service, WithUUID } from 'homebridge';
import { EventEmitter } from 'node:events';
import DeviceManager from './deviceManager.js';
import type KasaPythonPlatform from '../platform.js';
import type { CharacteristicDescriptor, ChildDevice, DescriptorContext, KasaDevice, SysInfo } from './deviceTypes.js';
import type { KasaPythonAccessoryContext } from '../platform.js';
export default abstract class HomeKitDevice {
readonly platform: KasaPythonPlatform;
kasaDevice: KasaDevice;
readonly category: Categories;
readonly categoryName: string;
readonly log: Logger;
protected deviceManager: DeviceManager | undefined;
homebridgeAccessory: PlatformAccessory<KasaPythonAccessoryContext>;
isUpdating: boolean;
protected previousSnapshot?: KasaDevice;
protected pollingInterval?: NodeJS.Timeout;
protected updateEmitter: EventEmitter<any>;
private static locks;
private pendingChanges;
protected getSysInfoDeferred: () => Promise<void>;
private primaryDescriptors;
private primaryService?;
constructor(platform: KasaPythonPlatform, kasaDevice: KasaDevice, category: Categories, categoryName: string);
private initializeAccessory;
private updateAccessory;
get id(): string;
get name(): string;
get manufacturer(): string;
get model(): string;
get serialNumber(): string;
get firmwareRevision(): string;
protected extractChildIndex(child: {
id?: string | number;
}): number;
protected makeLockKey(childId?: string | number): string;
protected withLock<T>(key: string, action: () => Promise<T>): Promise<T>;
protected shouldSkipUpdate(): boolean;
protected waitForUpdateOrDiscovery(): Promise<void>;
protected getSysInfo(): Promise<void>;
private fetchSysInfoInternal;
protected refreshAndUpdateCharacteristics(forceUpdate: boolean, skipFetch?: boolean): Promise<void>;
startPolling(): Promise<void>;
stopPolling(waitForCurrentUpdate?: boolean): Promise<void>;
updateAfterPeriodicDiscovery(force?: boolean): void;
protected setupPrimaryService(): void;
protected getPrimaryServiceType(): WithUUID<typeof this.platform.Service> | null;
protected buildPrimaryDescriptors(): CharacteristicDescriptor[];
protected registerCharacteristic(service: Service, type: WithUUID<new () => Characteristic>, onGet: () => Promise<CharacteristicValue>, onSet?: (value: CharacteristicValue) => Promise<void>): void;
protected buildDescriptorContext(child?: ChildDevice): DescriptorContext;
protected seedCharacteristicValue(service: Service, descriptor: CharacteristicDescriptor, context: DescriptorContext, errorPrefix: string): void;
protected updateDeviceField<K extends keyof SysInfo>(key: K, value: SysInfo[K]): void;
private genericOnGet;
private genericOnSet;
private executeDescriptorSet;
private shouldBypassSetLock;
protected updateAllServicesAndCharacteristics(forceUpdate: boolean): Promise<void>;
protected defaultValueForCharacteristic(type: WithUUID<new () => Characteristic>): CharacteristicValue;
protected resolveWithDebounce(key: string, currentHomeKitValue: CharacteristicValue, nextDeviceValue: CharacteristicValue, debouncePolls: number, force?: boolean): CharacteristicValue;
protected updateIfChanged<T extends CharacteristicValue>(service: Service, characteristic: Characteristic, alias: string, previousValue: T, nextValue: T, label?: string, force?: boolean): void;
protected addService(serviceCtor: WithUUID<typeof this.platform.Service>, name: string, subType?: string): Service;
protected updateValue(service: Service, characteristic: Characteristic, deviceAlias: string, value: Nullable<CharacteristicValue> | Error | HapStatusError, logUpdate?: boolean): void;
private isEnergyMonitoringCharacteristic;
abstract initialize(): Promise<void>;
abstract identify(): void;
}