UNPKG

homebridge-tuya-laundry

Version:

Allows washer/dryer cycle completion notifications using Tuya smart plugs with power meter, now using local control.

43 lines 1.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TuyaApiService = void 0; const TuyaOpenAPI_1 = __importDefault(require("../core/TuyaOpenAPI")); class TuyaApiService { constructor(credentials, log) { this.credentials = credentials; this.log = log; this.apiInstance = null; } static getInstance(credentials, log) { if (!TuyaApiService.instance) { TuyaApiService.instance = new TuyaApiService(credentials, log); } return TuyaApiService.instance; } async authenticate() { const { accessId, accessKey, username, password, countryCode, endpoint, appSchema } = this.credentials; this.apiInstance = new TuyaOpenAPI_1.default(endpoint, accessId, accessKey); try { const res = await this.apiInstance.homeLogin(Number(countryCode), username, password, appSchema); if (res && res.success) { this.log.info('Successfully authenticated with Tuya OpenAPI.'); } else { this.log.error('Authentication failed:', res ? res.msg : 'No response from API'); this.apiInstance = null; } } catch (error) { this.log.error('Error during Tuya API authentication:', error); this.apiInstance = null; } } getApiInstance() { return this.apiInstance; } } exports.TuyaApiService = TuyaApiService; //# sourceMappingURL=tuyaApiService.js.map