Class SwitchbotDevice

Represents a Switchbot Device.

Hierarchy (view full)

Indexable

  • [x: string]: any

Constructors

  • Initializes a new instance of the SwitchbotDevice class.

    Parameters

    • peripheral: Peripheral

      The peripheral object from noble.

    • noble: __module

      The Noble object.

    Returns SwitchbotDevice

Accessors

  • get connectionState(): string
  • Returns string

  • get onConnectHandler(): (() => Promise<void>)
  • Returns (() => Promise<void>)

      • (): Promise<void>
      • Returns Promise<void>

  • set onConnectHandler(func): void
  • Parameters

    • func: (() => Promise<void>)
        • (): Promise<void>
        • Returns Promise<void>

    Returns void

  • get onDisconnectHandler(): (() => Promise<void>)
  • Returns (() => Promise<void>)

      • (): Promise<void>
      • Returns Promise<void>

  • set onDisconnectHandler(func): void
  • Parameters

    • func: (() => Promise<void>)
        • (): Promise<void>
        • Returns Promise<void>

    Returns void

Methods

  • Sends a command to the device and awaits a response.

    Parameters

    • reqBuf: Buffer

      The command buffer.

    Returns Promise<Buffer>

    A Promise that resolves with the response buffer.

  • Connects to the device.

    Returns Promise<void>

    A Promise that resolves when the connection is complete.

  • Disconnects from the device.

    Returns Promise<void>

    A Promise that resolves when the disconnection is complete.

  • Discovers the device services.

    Returns Promise<Service[]>

    A Promise that resolves with the list of services.

  • Retrieves the device characteristics.

    Returns Promise<Chars>

    A Promise that resolves with the device characteristics.

  • Retrieves the device name.

    Returns Promise<string>

    A Promise that resolves with the device name.

  • Logs a message with the specified log level.

    Parameters

    • level: string

      The severity level of the log (e.g., 'info', 'warn', 'error').

    • message: string

      The log message to be emitted.

    Returns Promise<void>

  • Sets the device name.

    Parameters

    • name: string

      The new device name.

    Returns Promise<void>

    A Promise that resolves when the name is set.

  • Unsubscribes from the notify characteristic.

    Returns Promise<void>

    A Promise that resolves when the unsubscription is complete.