UNPKG

daikin-controller-cloud

Version:

Interact with Daikin Cloud devices and retrieve Tokens

64 lines 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DaikinCloudController = exports.RateLimitedError = void 0; const events_1 = require("events"); const device_js_1 = require("./device.js"); const oidc_client_js_1 = require("./onecta/oidc-client.js"); class RateLimitedError extends Error { retryAfter; constructor(message, retryAfter) { super(message); this.retryAfter = retryAfter; } } exports.RateLimitedError = RateLimitedError; /** * Daikin Controller for Cloud solution to get tokens and interact with devices */ class DaikinCloudController extends events_1.EventEmitter { #client; #devices = new Map(); constructor(config) { super(); this.#client = new oidc_client_js_1.OnectaClient(config, this); } /** * Get Daikin API Info * @returns {Promise<Object>} API Info object */ async getApiInfo() { return this.#client.requestResource('/v1/info'); } /** * Get pure Device Data from the Daikin cloud devices * @returns {Promise<Object>} pure Device details */ async getCloudDeviceDetails() { return await this.#client.requestResource('/v1/gateway-devices'); } /** * Get array of DaikinCloudDevice objects to interact with the device and get data */ async getCloudDevices() { await this.updateAllDeviceData(); return Array.from(this.#devices.values()); } async updateAllDeviceData() { const data = await this.getCloudDeviceDetails(); if (!Array.isArray(data)) { throw new Error('Invalid data received from cloud'); } data.forEach(d => { const device = this.#devices.get(d.id); if (device) { device.setDescription(d); } else { const newDevice = new device_js_1.DaikinCloudDevice(d, this.#client); this.#devices.set(newDevice.getId(), newDevice); } }); } } exports.DaikinCloudController = DaikinCloudController; //# sourceMappingURL=index.js.map