mqtt2ha
    Preparing search index...

    Class Discoverable<TComponentConfiguration, TStateMap>

    Base class for Home Assistant MQTT discoverable entities. Handles the MQTT discovery protocol and provides common functionality for all entity types.

    The type of state data this component can handle

    Type Parameters

    • TComponentConfiguration extends BaseComponentConfiguration

      The configuration type specific to this component

    • TStateMap extends Record<string, unknown>

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    attributesTopic: string

    MQTT topic for entity attributes

    availabilityTopic: string

    MQTT topic for entity availability status

    baseTopicName: string

    Base MQTT topic name for this entity

    The component configuration containing entity-specific settings

    configTopic: string

    MQTT topic for entity configuration

    identifier: string

    Unique identifier for this entity

    logger: Logger

    Logger instance for debugging and error reporting

    mqttClient: MqttClient

    The MQTT client instance used for communication

    The component settings including MQTT configuration

    stateChangedHandler: StateChangedHandler<TStateMap>

    Callback function to handle state changes

    stateTopics: StateTopicConfiguration[]

    List of MQTT topics for entity state

    wroteConfiguration: boolean = false

    Flag indicating whether configuration has been written to MQTT

    Methods

    • Sets additional attributes for the entity

      Parameters

      • attributes: Record<string, unknown>

        Key-value pairs of attributes to set

      Returns Promise<void>

    • Sets the availability state of the entity

      Parameters

      • availability: boolean

        True if the entity is available, false otherwise

      Returns Promise<void>

    • Sets the state of the entity

      Type Parameters

      • K extends string

      Parameters

      • topicName: K

        The name of the MQTT topic to publish the state to

      • state: TStateMap[K]

        The new state to set

      Returns Promise<void>

    • Sets the state of the entity

      Type Parameters

      • K extends string

      Parameters

      • topicName: K

        The name of the MQTT topic to publish the state to

      • state: TStateMap[K]

        The new state to set

      Returns void

    • Writes the entity's configuration to MQTT for Home Assistant discovery Also sets the entity's initial availability state if not manually managed

      Returns Promise<void>