Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HubitatApiService

A Nest.js service that allows for querying Hubitat's devices, sending commands to Hubitat's devices and exposes an observable providing device update events from Hubitat hub.

Hierarchy

  • HubitatApiService

Index

Constructors

constructor

  • Creates a new service instance. Use only for testing as service's creation is handled by the Dependency Injection.

    Parameters

    • configService: ConfigService

      A configuration service providing the configuration data required to establish a connection with the Hubitat hub.

    Returns HubitatApiService

Accessors

deviceUpdateObservable

  • Returns an new observer for device update events.

    example
    const subscription = hubitatApiService.deviceUpdateObservable
      .subscribe(eventData => console.log(JSON.stringify(eventData)));

    Returns Observable<DeviceEventDto>

    An observable that will provide all future device events.

Methods

getDeviceInfo

  • getDeviceInfo(deviceId: number): Promise<DeviceInfoDto | undefined>
  • Fetches full data for a specified device.

    example
    const deviceInfo = await hubitatApiService.getDeviceInfo(42);
    if (deviceInfo != null)
      console.log(`Device details: ${JSON.stringify(deviceInfo)}`);

    Parameters

    • deviceId: number

      Id of the device to fetch.

    Returns Promise<DeviceInfoDto | undefined>

    Returns details of a specified device. Returns undefined if the fetching the data failed.

getDevicesList

sendDeviceCommand

  • sendDeviceCommand(deviceId: number, command: string, value?: string | number): Promise<unknown | undefined>
  • Sends command to Hubitat's device. Only one value is supported as the Hubitat's Maker API doesn't support receiving two values. This makes it impossible to send commands like setLevel with the duration value.

    example
    await hubitatApiService.sendDeviceCommand(160, 'on');
    await hubitatApiService.sendDeviceCommand(160, 'setLevel', 75);

    Parameters

    • deviceId: number

      Id of the device this command needs to be sent.

    • command: string

      The command that needs to be send.

    • Optional value: string | number

      An optional value for the command.

    Returns Promise<unknown | undefined>

Generated using TypeDoc