procon-ip - v2.0.0
    Preparing search index...

    Class CommandService

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _endpoint: string = '/Command.htm'

    Endpoint path relative to IServiceConfig.controllerUrl.

    _method: HttpMethod = 'GET'

    HTTP method for this endpoint.

    _requestHeaders: Record<string, string>
    log: ILogger

    Accessors

    Methods

    • Perform the HTTP request configured for this service.

      The HTTP method, Authorization header (when basicAuth is enabled), and signal are always controlled by this method and cannot be overridden via init: an explicit init.method is ignored, and a caller-supplied init.signal is composed (via AbortSignal.any) with the internal timeout signal rather than replacing it. An external abort re-throws the original AbortError so callers can distinguish it from a timeout.

      Any other fetch init field (body, headers, cache, etc.) is passed through to fetch; caller headers are merged on top of the service's _requestHeaders.

      Parameters

      • init: RequestInit & { params?: Record<string, string | number> } = {}

        Optional fetch init plus a params shortcut. params, if provided, is serialised as key=value&key=value and appended to the URL without URL-encoding — values must already be URL-safe (numbers and ASCII letters are fine; spaces / special chars are not). This matches the wire format the controller's legacy endpoints expect (e.g. literal commas in ?MAN_DOSAGE=0,60).

      Returns Promise<Response>

      The raw Response for the caller to parse.

      BadCredentialsError on HTTP 401 or 403.

      BadStatusCodeError on any other 4xx/5xx response.

      RequestTimeoutError if the request exceeds the configured timeout.

    • Manual chlorine dosage for dosageTime seconds.

      Parameters

      • dosageTime: number

      Returns Promise<number>

      The dosage duration on success, or -1 after three failed attempts.

      import { CommandService, Logger } from 'procon-ip';

      const svc = new CommandService(
      { controllerUrl: 'http://192.168.2.3', basicAuth: false, timeout: 5000 },
      new Logger(),
      );
      const seconds = await svc.setChlorineDosage(60); // dose for 60s
    • Trigger a manual dosage.

      Two error modes, distinguished:

      • Invalid input (non-finite dosageDuration): throws ProconIpError immediately, before any HTTP traffic. The caller's bug, surface it.
      • Per-attempt request failure (timeout, HTTP 5xx, network error): caught internally and retried up to three times. Failures are logged at debug; after the third attempt the method returns -1.

      Parameters

      • dosageTarget: DosageTarget

        Target relay (chlorine / pH-minus / pH-plus).

      • dosageDuration: number

        Duration in seconds. Fractional inputs are truncated; the returned value reflects the truncated seconds.

      Returns Promise<number>

      The (truncated) duration on success, or -1 after three failures.

      ProconIpError if dosageDuration is not a finite number.

    • Manual pH-minus dosage for dosageTime seconds.

      Parameters

      • dosageTime: number

      Returns Promise<number>

    • Manual pH-plus dosage for dosageTime seconds.

      Parameters

      • dosageTime: number

      Returns Promise<number>