MELCloud & MELCloud Home API for Node.js - v60.5.0
    Preparing search index...

    Class ClassicAPI

    Low-level API adapter exposing all MELCloud HTTP endpoints. Methods are grouped by supported device types.

    Best-effort getters return Result<T> so callers can branch on the typed failure shape (network / unauthorized / rate-limited / validation / server) instead of catching opaque exceptions.

    Mutations (update*, login) and sync (fetch) keep their throw-on-failure contract — symmetric with Home's updateValues and list.

    Every method returns the unwrapped payload (no { data } wrapper). Transport metadata (status, headers) lives inside the SDK on request<T>(); consumers don't see it. Applied uniformly across both Classic and Home so the public surface is symmetric.

    Hierarchy

    • BaseAPI
      • ClassicAPI

    Implements

    Index
    logger: Logger
    settingManager?: SettingManager
    • get isRateLimited(): boolean

      Whether the upstream rate-limit gate is currently holding a pause window after a recent 429 Retry-After response.

      Returns boolean

      true while the SDK is intentionally failing fast.

    • get locale(): string | undefined

      BCP-47 locale supplied via ClassicAPIConfig.locale, or undefined when unset. Surfaced through ClassicAPIAdapter so facades thread it into getChartLineOptions and report labels stay consistent with the configured locale without a mutable global.

      Returns string | undefined

      The configured BCP-47 locale tag, or undefined.

    • Releases the auto-sync timer and any retry-guard window; the instance must not be reused after disposal.

      Returns void

    • Sign in with explicit credentials. The server refuses them in protocol-specific ways, which the subclass's doAuthenticate hook normalises into AuthenticationError. Successful return guarantees the registry reflects server state — the post-auth sync is enforced here so subclasses cannot forget it.

      Use resumeSession for a best-effort restore from persisted credentials that logs + swallows errors.

      Credentials are persisted only once the server accepts them: a rejected attempt leaves the stored pair and any live session untouched (the backoff still arms and the error still surfaces).

      Parameters

      Returns Promise<void>

      AuthenticationError when the server refuses the credentials.

      RegistrySyncError when the enforced post-auth sync fails — the sync's own failure (a validation rejection, a transport failure, any registry error) rides its cause. The credential check happened FIRST, so the session is left signed in and the credentials persisted: this rejection says "signed in, but the registry could not be verified", never "sign-in refused". The dedicated type is what lets callers branch on that difference without re-deriving it from isAuthenticated() — a discriminator that misreads a transport blip during an account switch over a pre-existing live session as "signed in, stale list".

    • Cancels any pending auto-sync timer; subsequent setSyncInterval or sync calls re-arm it.

      Returns void

    • Sync check first; when it reads false, a NON-DESTRUCTIVE probe — one registry sync, which exercises the persisted session without touching it — and only if that still leaves us unauthenticated, the best-effort resumeSession fallback. The order matters: resumeSession runs a full sign-in, which spends a real login attempt (server-side throttle counters, the local backoff on a rejection) and replaces a session that may have been merely unexercised (a boot-time context fetch that lost the network reads unauthenticated while a perfectly valid refresh token sits in storage).

      Every rung reads the RECORDED verdict, not the bare session: a stored credential the server has definitively refused (see resumeSession) answers false here even while isAuthenticated() still reads true over a session the refusal deliberately did not clear — only an ACCEPTED sign-in restores the true answer.

      Returns Promise<boolean>

      true when a session is usable afterwards.

    • Retrieve a parsed, paginated error log for the specified devices. Filters out entries with invalid dates or empty messages.

      Parameters

      • query: ErrorLogQuery

        The error log query parameters (date range, pagination).

      • deviceIds: number[] = ...

        ClassicDevice IDs to fetch errors for; defaults to all devices.

      Returns Promise<Result<ClassicErrorLog>>

      Parsed error log with pagination metadata, or a typed failure.

    • Post-construction lifecycle hook. Every subclass create() factory must delegate to this method — it is the sole path that guarantees the invariant at instance-creation time: a successful return leaves the registry populated whenever credentials or a persisted session are available.

      Two-branch template:

      1. tryReuseSession — if the subclass can reuse a persisted session (and populate the registry in the process), we are done.
      2. Otherwise, resumeSession runs — best-effort restore from persisted credentials. Does nothing (silently) if no credentials are persisted, so the "no creds + no session" case falls through to a documented empty state.

      Callers should check isAuthenticated after create() returns if they need to distinguish "empty state" from "ready".

      Returns Promise<void>

    • Log out: the inverse of authenticate. Clears the persisted session, the stored username/password and the automatic-login backoff, stops the auto-sync timer, and empties the registry — so isAuthenticated reads false and no stale devices linger.

      User-initiated, so unlike a rejected sign-in it neither arms the backoff nor emits onAuthenticationLost. A subsequent authenticate is the only way back in.

      Returns void

    • Notify any registered events.onSyncComplete observer that a sync just landed. Routed through the lifecycle emitter so a misbehaving callback cannot break the caller.

      Parameters

      • ...args: [params?: SyncParams]

        SyncCallback-shaped payload.

      Returns Promise<void>

    • Best-effort session restore from persisted credentials.

      Reads username/password from the SettingManager and signs in. Unlike authenticate, failures are logged and swallowed — the method never throws. That covers the enforced post-auth sync too: authenticate surfaces what enforceRegistrySync raises as a RegistrySyncError, and this method catches it like any other rejection rather than letting a registry failure reach a lifecycle caller. Use it from lifecycle hooks (init, auth retry, ensureSession) where a stale or missing persisted credential must not crash the caller.

      SINGLE-FLIGHT: concurrent calls share one attempt — the lifecycle paths that race at boot (a background initialize, the first request's ensureSession, a reactive auth failure) collapse onto ONE sign-in round-trip, and every caller's verdict describes that shared attempt. Without the memo, two callers could both pass the login-backoff gate before either refusal armed it, spending two sign-ins against an upstream whose measured throttle threshold was four in seventy seconds.

      A refusal it swallows is also RECORDED (a definitive rejection only — never a throttle or a transport failure): the stored session stays untouched, but the sync-cycle epilogue stops reading it as signed-in until a sign-in is accepted again.

      On success, the registry is populated (delegates to authenticate).

      Returns Promise<boolean>

      true when the sign-in round-trip was ACCEPTED — including one whose enforced post-auth sync then failed, because the session it established stands; false for "no persisted credentials", "sign-ins are backed off" and "the server refused the credentials" (indistinguishable by the return value alone — check the logger / isAuthenticated if the distinction matters).

    • Reschedules the auto-sync timer.

      The timer is unref'd, so it never keeps the Node event loop alive on its own — auto-sync still fires on cadence whenever the host application has another reason to stay running (HTTP server, other timers, open streams). Apps that must run indefinitely should provide their own keep-alive rather than relying on this timer.

      Parameters

      • minutes: number | false

        Cadence in minutes; pass false to disable.

      Returns void

    • Run the initial session restore, honoring the configured mode. initialize never rejects by design (probe and resume failures are swallowed and surfaced through the lifecycle events), so the background variant only needs the fire-and-forget form.

      Parameters

      • OptionalshouldResumeInBackground: boolean

        When true, the restore runs off the caller's critical path and create() resolves immediately.

      Returns Promise<void>

    • Update the user's language on the server if it differs from the current locale.

      Parameters

      • language: string

        The language code to set.

      Returns Promise<void>

    • Create and initialize a MELCloud Classic API instance.

      Delegates post-construction setup to BaseAPI.initialize so the #1281-class invariant is enforced uniformly: on return, either the registry is populated or the instance is in a documented empty state (no credentials, no persisted session).

      Parameters

      • Optionalconfig: ClassicAPIConfig

        Optional configuration for the Classic API client.

      Returns Promise<ClassicAPI>

      The initialized ClassicAPI instance.