Options
All
  • Public
  • Public/Protected
  • All
Menu

Class FhemClient

Hierarchy

  • FhemClient

Index

Constructors

Properties

Methods

Constructors

constructor

  • Creates and initialises an instance of FhemClient.

    throws

    Error with code 'EFHEMCL_INVLURL' in case options.url is not a valid url string.

    Parameters

    • options: Options

      An object specifying FHEM- and request-related settings.

    • Optional logger: Logger

      You can pass any logger instance as long as it provides the methods log(level, ...args), debug, info, warn and error.

    Returns FhemClient

Properties

expirationPeriod

expirationPeriod: number = 0

Time in millis after which to discard a failed request.
If this has been set to a positive value and a request fails, then, if the respective error code has a positive retry interval, it will be reissued after the specified time until it succeeds or expirationPeriod is exceeded.
If set to 0 (the default), a failed request will be discarded immediately and an Error will be thrown. See property Options.retryIntervals of options param of FhemClient.constructor.

Methods

callFn

  • callFn(name: string, functionName: string, passDevHash?: boolean, functionReturnsHash?: boolean, ...args: (string | number | false | true)[]): Promise<string | number | void | (string | number)[] | Map<string | number, string | number>>
  • Request FHEMWEB to call a registered module function. This method corresponds to FHEM's Perl function 'CallFn'.

    throws

    Error with code 'EFHEMCL_RES' in case of response error (default retry interval: 500 ms).

    throws

    Error with code 'EFHEMCL_ABRT' in case the response closed prematurely (default retry interval: 500 ms).

    throws

    Error with code 'EFHEMCL_TIMEDOUT' in case connecting timed out (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_CONNREFUSED' in case the connection has been refused (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_NETUNREACH' in case the network is unreachable (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_CONNRESET' in case the connection has been reset by peer.

    throws

    Error with code 'EFHEMCL_REQ' in case of a different request error.

    throws

    Error with code 'EFHEMCL_AUTH' in case of wrong username or password.

    throws

    Error with code 'EFHEMCL_WEBN' in case of a wrong FHEM 'webname'.

    throws

    Error with code 'EFHEMCL_NOTOKEN' in case FHEMWEB does use but not send the CSRF Token.

    throws

    Error with code 'EFHEMCL_CF_FHEMERR' in case FHEM returned an error message instead of the function's return value,
    e. g. if functionName exists in the module hash, but the corresponding value names a function that doesn't exist.

    throws

    Error with code 'EFHEMCL_CF_ODDLIST' in case functionReturnsHash === true and the function returned an odd-sized list.

    Parameters

    • name: string

      The name of the device to call the function for.

    • functionName: string

      The name of the function as used to register it in the module hash.

    • Optional passDevHash: boolean

      Whether the ref to the instance hash of the device should be passed to the function as first argument. Defaults to false.

    • Optional functionReturnsHash: boolean

      Whether the function returns a hash that should be transformed to a Map. Defaults to false.

      If the function returns a hash (literal, no ref), which is just an even-sized list, you must indicate this.
      Failing to do so will give you an array of key/value pairs.

      On the other hand, if you provide true for this and the function returns an odd-sized list, the Promise will be rejected.
      This parameter is meaningless if the function returns a scalar.

    • Rest ...args: (string | number | false | true)[]

      The arguments to be passed to the function.
      If an argument is undefined, the function will get Perl's 'undef' for that argument.
      If an argument is true or false, the function will get 1 or "", respectively.

    Returns Promise<string | number | void | (string | number)[] | Map<string | number, string | number>>

    A Promise that will be resolved with the result on success or rejected with one of the following errors.

    If the function cannot be found in the module hash or returns 'undef', the result will be undefined.

    If the function returns a scalar or a list, the result will be a value or an array, respectively.
    Furthermore, if the list is even-sized and functionReturnsHash === true, the result will be a Map.

    In either case, numbers will be returned as numbers, not as strings.

execCmd

  • execCmd(cmd: string): Promise<string | number | void>
  • Request FHEMWEB to execute a FHEM command.

    throws

    Error with code 'EFHEMCL_RES' in case of response error (default retry interval: 500 ms).

    throws

    Error with code 'EFHEMCL_ABRT' in case the response closed prematurely (default retry interval: 500 ms).

    throws

    Error with code 'EFHEMCL_TIMEDOUT' in case connecting timed out (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_CONNREFUSED' in case the connection has been refused (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_NETUNREACH' in case the network is unreachable (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_CONNRESET' in case the connection has been reset by peer.

    throws

    Error with code 'EFHEMCL_REQ' in case of a different request error.

    throws

    Error with code 'EFHEMCL_AUTH' in case of wrong username or password.

    throws

    Error with code 'EFHEMCL_WEBN' in case of a wrong FHEM 'webname'.

    throws

    Error with code 'EFHEMCL_NOTOKEN' in case FHEMWEB does use but not send the CSRF Token.

    Parameters

    • cmd: string

      The FHEM command to execute

    Returns Promise<string | number | void>

    A Promise that will be resolved with the result in its actual data type on success or rejected with one of the following errors.

execPerlCode

  • execPerlCode(code: string): Promise<string | number | void>
  • Request FHEMWEB to execute Perl code.

    throws

    Error with code 'EFHEMCL_RES' in case of response error (default retry interval: 500 ms).

    throws

    Error with code 'EFHEMCL_ABRT' in case the response closed prematurely (default retry interval: 500 ms).

    throws

    Error with code 'EFHEMCL_TIMEDOUT' in case connecting timed out (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_CONNREFUSED' in case the connection has been refused (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_NETUNREACH' in case the network is unreachable (default retry interval: 10000 ms).

    throws

    Error with code 'EFHEMCL_CONNRESET' in case the connection has been reset by peer.

    throws

    Error with code 'EFHEMCL_REQ' in case of a different request error.

    throws

    Error with code 'EFHEMCL_AUTH' in case of wrong username or password.

    throws

    Error with code 'EFHEMCL_WEBN' in case of a wrong FHEM 'webname'.

    throws

    Error with code 'EFHEMCL_NOTOKEN' in case FHEMWEB does use but not send the CSRF Token.

    Parameters

    • code: string

      A string containing valid Perl code. Be sure to use ';;' to separate multiple statements.

    Returns Promise<string | number | void>

    A Promise that will be resolved with the result in its actual data type on success or rejected with one of the following errors.

Generated using TypeDoc