Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HAInstance

Main entry point to the module. A object of this class represents a running home assistant instance that exposes the websocket and rest API:s.

Instances of this class should be created using the static create method.

export

Hierarchy

  • HAInstance

Index

Constructors

Private constructor

  • new HAInstance(wsConnection: Connection, rest: RESTClient): HAInstance

Properties

Readonly rest

rest: RESTClient

state$

state$: Observable<StateChangedEvent<HassEntity>> = new Observable<StateChangedEvent<HassEntity>>((subs) => {void this.wsConnection.subscribeEvents((evt: StateChangedEvent<HassEntity>) => {subs.next(evt);}, 'state_changed').then((f) => (this.unSubscribe = f));}).pipe(share())

A hot observable that will emit when there is a state change in the Home Assistant system.

Private Readonly wsConnection

wsConnection: Connection

Methods

close

  • close(): void

entityState$

  • Returns a hot observable that will emit when the state of the given entity changes.

    Type parameters

    • T: HassEntityBase

      Type of the entity to monitor.

    Parameters

    • id: string

      Id of the entity to monitor.

    Returns Observable<StateChangedEvent<T>>

getEntity

  • getEntity<T>(id: string, type?: undefined | { constructor: any }): T
  • Returns a Entity instance or a object of a derived class representing the state of a given entity in the Home Assistant system.

    Type parameters

    • T: Entity = Entity

      A type derived from Entity matching the type of entity represented by the given id.

    Parameters

    • id: string

      Entity id

    • Optional type: undefined | { constructor: any }

      Optional Class function of T , if omitted a object of class Entity will be returned.

    Returns T

    A object of type T.

getService

  • getService<T>(type: { constructor: any }): T

Private unSubscribe

  • unSubscribe(): undefined

Static create

  • Factory function creating new instances of the class.

    Parameters

    • host: string

      Hostname (and port) of the running home assistant system to connect to.

    • token: AccessToken

      A (long lived) token authorizing access to the Home Assistant system.

    Returns Promise<HAInstance>

Generated using TypeDoc