import { EventEmitter } from 'node:events' import * as HomeKitTypes from 'hap-nodejs/dist/lib/definitions' import { CharacteristicValue, HAP, Logging, Service } from 'homebridge' import { YeelightDeviceProps } from './yeelight/yeelight.typing' // Config export type Config = { reConnectThreshold: number reConnectFailureThreshold: number reConnectFailureThresholdDefault: number reConnectFailureThresholdIncreaseLimit: number requestConnectDebounceThreshold: number requestPropertyDebounceThreshold: number requestCharacteristicTimeout: number } // Init export function initDevice (props: { log: Logging; hap: HAP }): void // Register export type DeviceResponseValueMapping = Record export type DeviceRegisterConfig = { service?: Service name?: string, get: { defaultValue: any, formatter: (valueMapping?: DeviceResponseValueMapping) => PropertyValue } set?: { property: any formatter: (value: CharacteristicValue, previousProperty: DeviceResponseValueMapping) => any validator?: (value: CharacteristicValue, previousProperty: DeviceResponseValueMapping) => boolean } } export type EventAdaptorConfig = { service?: Service name?: string, get: { defaultValue: any, formatter: (valueMapping?: DeviceResponseValueMapping) => PropertyValue } set?: { property: any formatter: (value: CharacteristicValue, previousProperty: DeviceResponseValueMapping) => any validator?: (value: CharacteristicValue, previousProperty: DeviceResponseValueMapping) => boolean } } // Common export type ValueOf = T[keyof T] export type Resolve = (...args: any[]) => void export type HomeKitTypes = ValueOf export type PropertyKey = string export type PropertyValue = string | number | boolean export type DeviceConfig = { name: string; address: string; token: string; } export type DeviceConfigs = DeviceConfig[] export class DeviceInstance { public id: string public did: string public timeout: number // MIoT public miioCall (action: 'get_properties', specQuery: MIoTSpecsGetQuery): MIoTSpecsResponse[] public miioCall (action: 'set_properties', specQuery: MIoTSpecsSetQuery): MIoTSpecsResponse[] // MiIO public miioCall (action: 'get_prop', specQuery: MIIOSpecGetQuery): MIIOSpecResponse public miioCall (action: string, specQuery: PropertyValue[]): void } // Mi Base export type MiIdentify = { name: string; token: string; address: string; } export type MiDeviceProps = { identify: MiIdentify service: Service specs: S } export class MiDevice { constructor (props: MiDeviceProps) } // MIoT export type MIoTSpecRaw = { siid: number, piid: number } export type MIoTSpecRawMapping = { [name: string]: MIoTSpecRaw } export type MIoTSpec = { name: string } & MIoTSpecRaw export type MIoTSpecMapping = { [name: string]: MIoTSpec } export type MIoTSpecGetQuery = MIoTSpec & { did: string } export type MIoTSpecSetQuery = MIoTSpec & { did: string; value: PropertyValue } export type MIoTRegisterConfig = DeviceRegisterConfig export type MIoTSpecsGetQuery = MIoTSpecGetQuery[] export type MIoTSpecsSetQuery = MIoTSpecSetQuery[] export type MIoTSpecsResponse = MIoTSpec & { did: string; value: T } export class MIoTDevice extends MiDevice { public addCharacteristicListener (type: HomeKitTypes, config: MIoTRegisterConfig): void } // MiIO export type MIIOSpec = string export type MIIOSpecMapping = { [name: string]: MIIOSpec } export type MIIOSpecGetQuery = MIIOSpec[] export type MIIOSpecResponse = PropertyValue[] export type MIIORegisterConfig = DeviceRegisterConfig export class MIIODevice extends MiDevice { public addCharacteristicListener (type: HomeKitTypes, config: MIIORegisterConfig): void } // Yeelight export class YeelightDevice extends EventEmitter { constructor (props: YeelightDeviceProps) public addEventAdaptor (type: HomeKitTypes, config: EventAdaptorConfig): void } export type { YeelightIdentify, YeelightProperties } from './yeelight/yeelight.typing' export { YEELIGHT_PROPERTY, YEELIGHT_VALUE, YEELIGHT_STATE, YEELIGHT_COMMAND } from './yeelight/yeelight.constant' // Shared export class Share { public log: Logging public hap: HAP public config: Config } export const Shared: InstanceType // Utils export function formatMIoTSpecs (v: T): { [K in keyof T]: ValueOf & { name: string } }