import { Validator } from "jsonschema"; import { IClientPublishOptions } from "mqtt"; import { BehaviorSubject, Observable, Subject } from "rxjs"; import { HomieElement } from "./HomieElement"; import { HomieNode } from "./HomieNode"; import { DictionaryStore } from "./misc"; import { MQTTConnectOpts, HomieDeviceMode, HomieID, DevicePointer, HomieVersion, ObjectMap, NodeDescription, IDAttribute } from "./model"; import { DeviceAttributes, DeviceDescription, DeviceState } from "./model"; import { MqttMessage, RxMqtt } from "./mqtt"; export declare const HD_ATTR_STATE = "$state"; export declare const HD_ATTR_DESCRIPTION = "$description"; export declare const HD_ATTR_LOG = "$log"; export declare const HD_ATTR_ALERT = "$alert"; export declare const HOMIE_LOG_LEVEL_DEBUG = "debug"; export declare const HOMIE_LOG_LEVEL_INFO = "info"; export declare const HOMIE_LOG_LEVEL_WARN = "warn"; export declare const HOMIE_LOG_LEVEL_ERROR = "error"; export declare const HOMIE_LOG_LEVEL_FATAL = "fatal"; export declare const HOMIE_LOG_LEVELS: readonly ["debug", "info", "warn", "error", "fatal"]; export declare type HomieLogLevel = typeof HOMIE_LOG_LEVELS[number]; export declare function isHomieLogLevel(value: string): value is HomieLogLevel; export interface HomieLogEvent { deviceId: HomieID; level: HomieLogLevel; message: string; } export interface HomieAlertEvent { deviceId: HomieID; alertId: string; message: string | null; } export declare const DeviceDescriptionSchema: any; export declare class HomieDevice extends HomieElement { readonly mode: HomieDeviceMode; protected readonly sharedMqttClient: boolean; protected readonly rootTopic: string; readonly topic: string; readonly pointer: DevicePointer; protected _rootState$: BehaviorSubject; rootState$: Observable; get rootState(): DeviceState | undefined; protected set rootState(value: DeviceState | undefined); get deviceState(): DeviceState; protected set deviceState(value: DeviceState); protected _logEvent$: Subject; logEvent$: Observable; protected _alertEvent$: Subject; alertEvent$: Observable; protected _alerts$: BehaviorSubject>; alerts$: Observable>; get alerts(): Map; readonly state$: Observable; /** * @description * Will return the combined state of this device and (if applicable) the connected root device. * Note: If you only want the deviceState use the deviceState attribute. */ get state(): DeviceState; protected mqttOpts: MQTTConnectOpts; protected mqtt: RxMqtt; get homie(): HomieVersion; get version(): number; protected set version(value: number); private _descriptionUpdateNeeded; get descriptionUpdateNeeded(): boolean; set descriptionUpdateNeeded(value: boolean); protected validator: Validator; protected nodeStore: DictionaryStore; nodes$: Observable>; nodesChange$: Observable>; get nodes(): ObjectMap; constructor(attributes: Partial & IDAttribute, mqttOrMqttOptions: MQTTConnectOpts | RxMqtt, mode?: HomieDeviceMode); static fromDescription(id: HomieID, description: DeviceDescription, mqttOrMqttOptions: MQTTConnectOpts | RxMqtt, mode?: HomieDeviceMode): HomieDevice; updateFromDescription(description?: DeviceDescription): Promise; protected updateNodes(nodeDescriptions: ObjectMap): Promise; getDescription(): DeviceDescription; onInit(): Promise; subscribeTopics(): void; /** * @description * Adds a node to the device and update the 'nodes' attribute list. * Please note: * This will not take care of initializing the node or publishing the '$description' attribute. * In case the device is already initialized. Please use {@link deviceChangeTransaction} or {@link deviceChangeTransactionAsync} to wrap this and ensure to call the node's {@link HomieNode.onInit} method. * @param node : new node to add (also accepts undefined values for convinience) * @returns added node */ add(node: T): T; /** * Returns node for id. * * @param nodeId id of node or nullish for convinience * @returns node for the given id. or undefined if node was not found */ get(nodeId: string | null | undefined): T | undefined; /** * Removes a node from the device. * Please note: * This will not take care of wiping or destroying the node. Neither will the '$description' attribute be published or anything else needed in case the device is already initialized. * In case the device is already initialized. Please use {@link deviceChangeTransaction} or {@link deviceChangeTransactionAsync} to wrap this and ensure to call the node's {@link HomieNode.onDestroy} method. * @param node Node to remove or node id to remove - or nullish for convinience * @returns Removed node or undefined if the node was not found. */ remove(node: T | string | null | undefined): T | undefined; protected mqttPublish$(path: string, value: string | null | undefined, options?: IClientPublishOptions, publishEmpty?: boolean): Observable; protected mqttSubscribe(path: string, retained?: boolean): Observable; protected publishAttribute$(attrName: string, data: any, opts?: IClientPublishOptions): Observable; protected publishDescription$(): Observable; sendStateUpdate$(state?: DeviceState | null): Observable; updateState$(state: DeviceState): Observable; /** * Publishes a log message to `$log/{level}`. Non-retained, QoS 1. * Only works in device mode. * @param level Log level (debug, info, warn, error, fatal) * @param message Log message text */ publishLog$(level: HomieLogLevel, message: string): Observable; /** * Publishes an alert to `$alert/{alertId}`. Retained, QoS 2. * Only works in device mode. * @param alertId Alert identifier (e.g. "$lowbattery", "$unreach") * @param message Alert message text */ publishAlert$(alertId: string, message: string): Observable; /** * Clears an alert by publishing empty payload to `$alert/{alertId}`. Retained, QoS 2. * Only works in device mode. * @param alertId Alert identifier to clear */ clearAlert$(alertId: string): Observable; /** * In case changes to the device's structure are performed after the device is already initialized and published, use this method to wrap the changes in a callback (cb) function. * An `init` state will be published before the callback is executed and in case of any changes the `$description` attribute will be published before the state is set back to `ready` again. * @param cb async callback with changes to device's structure. Return true on success, false on failure. * @returns Observable with the callbacks boolean return value */ deviceChangeTransaction(cb: () => Promise): Observable; /** * In case changes to the device's structure are performed after the device is already initialized and published, use this method to wrap the changes in a callback (cb) function. * An `init` state will be published before the callback is executed and in case of any changes the `$description` attribute will be published before the state is set back to `ready` again. * @param cb async callback with changes to device's structure. Return true on success, false on failure. * @returns Promise with the callbacks boolean return value */ deviceChangeTransactionAsync(cb: () => Promise): Promise; onConnect(): Promise; onError(err: Error): void; private disconnect; protected validateDescription(description: DeviceDescription): boolean; wipe$(): Observable; onDestroy(): Promise; }