diff --git a/lib/base_accessory.js b/lib/base_accessory.js index 99dddd84..d5dbd274 100644 --- a/lib/base_accessory.js +++ b/lib/base_accessory.js @@ -51,7 +51,7 @@ class BaseAccessory { } // Service - if (this.subServices.length == 0) { + if (this.subServices.length == 0 || this.subServices.length == 1) { // Service this.service = this.homebridgeAccessory.getService(this.serviceType); if (this.service) { diff --git a/lib/outlet_accessory.js b/lib/outlet_accessory.js index 82bfef25..2db81f14 100644 --- a/lib/outlet_accessory.js +++ b/lib/outlet_accessory.js @@ -38,7 +38,12 @@ class OutletAccessory extends BaseAccessory { continue; } var value = status.value - const service = this.homebridgeAccessory.getService(subType); + let service + if (this.subTypeArr.length == 1) { + service = this.service; + }else{ + service = this.homebridgeAccessory.getService(subType); + } this.setCachedState(service.displayName, value); if (this.isRefresh) { service diff --git a/lib/switch_accessory.js b/lib/switch_accessory.js index 333b3dc3..d4a12221 100644 --- a/lib/switch_accessory.js +++ b/lib/switch_accessory.js @@ -35,7 +35,12 @@ class SwitchAccessory extends BaseAccessory { continue; } var value = status.value - const service = this.homebridgeAccessory.getService(subType); + let service + if (this.subTypeArr.length == 1) { + service = this.service; + }else{ + service = this.homebridgeAccessory.getService(subType); + } this.setCachedState(service.displayName, value); if (this.isRefresh) { service diff --git a/lib/tuyaopenapi.js b/lib/tuyaopenapi.js index 604a0489..3bb7765e 100644 --- a/lib/tuyaopenapi.js +++ b/lib/tuyaopenapi.js @@ -170,7 +170,7 @@ class TuyaOpenAPI { 'lang': this.lang, 'dev_lang': 'javascript', 'dev_channel': 'homebridge', - 'devVersion': '1.4.0', + 'devVersion': '1.4.1', }; this.log.log(`TuyaOpenAPI request: method = ${method}, endpoint = ${this.endpoint}, path = ${path}, params = ${JSON.stringify(params)}, body = ${JSON.stringify(body)}, headers = ${JSON.stringify(headers)}`); diff --git a/lib/tuyashopenapi.js b/lib/tuyashopenapi.js index 428e6d5b..6af519a0 100644 --- a/lib/tuyashopenapi.js +++ b/lib/tuyashopenapi.js @@ -2,17 +2,17 @@ const axios = require('axios').default; const Crypto = require('crypto-js'); const uuid = require('uuid'); const nonce = uuid.v1(); -const DEFAULT_ENDPOINT = 'https://openapi.tuyacn.com'; class TuyaSHOpenAPI { constructor(accessId, accessKey, username, password, countryCode, appSchema, log, lang = 'en') { - this.endpoint = DEFAULT_ENDPOINT; + this.countryCode = countryCode; + this.endpoint = (this.countryCode && this.countryCode == 86)? 'https://openapi.tuyacn.com' : 'https://openapi.tuyaus.com' this.access_id = accessId; this.access_key = accessKey; this.lang = lang; this.username = username; this.password = password; - this.countryCode = countryCode; + this.appSchema = appSchema; this.log = log; @@ -46,7 +46,7 @@ class TuyaSHOpenAPI { 'schema': this.appSchema }); let { access_token, refresh_token, uid, expire_time , platform_url} = res.result; - this.endpoint = platform_url ? platform_url : DEFAULT_ENDPOINT; + this.endpoint = platform_url ? platform_url : this.endpoint; this.tokenInfo = { access_token: access_token, refresh_token: refresh_token, @@ -164,7 +164,7 @@ class TuyaSHOpenAPI { 'lang': this.lang, 'dev_lang': 'javascript', 'dev_channel': 'homebridge', - 'devVersion': '1.4.0', + 'devVersion': '1.4.1', }; this.log.log(`TuyaOpenAPI request: method = ${method}, endpoint = ${this.endpoint}, path = ${path}, params = ${JSON.stringify(params)}, body = ${JSON.stringify(body)}, headers = ${JSON.stringify(headers)}`); diff --git a/package.json b/package.json index 053f65e0..057f1894 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-tuya-platform", - "version": "1.4.0", + "version": "1.4.1", "description": "Official Homebridge plugin for Tuya Open API, maintained by the Tuya Developer Team.", "main": "index.js", "scripts": {