Skip to content

Commit fa13489

Browse files
author
Jurgen Heine
committed
fix not finding contact sensor
1 parent 667be23 commit fa13489

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

api.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ module.exports = {
33
try {
44
homey.app.log("Connect from settings received.");
55
await homey.app.connectToTuyaApi();
6-
if(homey.app.logger.lastConnectionError!=null){
7-
return homey.app.logger.lastConnectionError;
8-
}
9-
return null;
106
} catch (err) {
117
homey.app.log(err);
128
return err;
139
}
10+
if(homey.app.logger.lastConnectionError!=null){
11+
throw new Error(homey.app.logger.lastConnectionError);
12+
}
13+
return null;
1414
},
1515

1616
async refreshScenes({ homey, query }) {

drivers/tuyacontact/driver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TuyaCoverDriver extends TuyaBaseDriver {
1414
throw new Error("Please configure the app first.");
1515
}
1616
else {
17-
let covers = this.get_devices_by_type("smokeSensor");
17+
let covers = this.get_devices_by_type("contactSensor");
1818
for (let tuyaDevice of Object.values(covers)) {
1919
let capabilities = [];
2020
capabilities.push("alarm_contact");

lib/tuyashopenapi.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ class TuyaSHOpenAPI {
4646
'password': md5pwd,
4747
'schema': this.appSchema
4848
});
49-
let { access_token, refresh_token, uid, expire_time, platform_url } = res.result;
50-
this.endpoint = platform_url ? platform_url : this.endpoint;
51-
this.tokenInfo = {
52-
access_token: access_token,
53-
refresh_token: refresh_token,
54-
uid: uid,
55-
expire: expire_time * 1000 + new Date().getTime(),
56-
};
57-
49+
if(res.success){
50+
let { access_token, refresh_token, uid, expire_time, platform_url } = res.result;
51+
this.endpoint = platform_url ? platform_url : this.endpoint;
52+
this.tokenInfo = {
53+
access_token: access_token,
54+
refresh_token: refresh_token,
55+
uid: uid,
56+
expire: expire_time * 1000 + new Date().getTime(),
57+
};
58+
this.log.lastConnectionError =null;
59+
}else{
60+
let msg = "Code: "+res.code+"; msg: "+ res.msg;
61+
this.log.lastConnectionError = msg;
62+
throw new Error(msg);
63+
}
5864
return;
5965
}
6066

@@ -168,7 +174,7 @@ class TuyaSHOpenAPI {
168174
this.log.logConnectionError(e);
169175
return;
170176
}
171-
this.log.lastConnectionError = null;
177+
172178

173179
let now = new Date().getTime();
174180
let access_token = this.tokenInfo.access_token || '';

locales/nl.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"settings": {
33
"apiToUse": "Kies de gewenste API(s)",
4-
"appid": "Official api acces id",
5-
"appsecret": "Official api acces secret, voor meer informatie: ",
4+
"appid": "Official api acces id, voor meer informatie: ",
5+
"appsecret": "Official api acces secret",
66
"username": "Gebruikersnaam",
77
"title": "Tuya cloud instellingen",
88
"authentication": "Authenticatie instellingen",

settings/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ <h1><span data-i18n="settings.title"></h1>
3636
<input id="password" type="password" value="" />
3737
</div>
3838
<div class="field row">
39-
<label for="appid"><span data-i18n="settings.appid"><a target="_blank" href="https://community.homey.app/t/app-pro-tuya-cloud/21313">https://community.homey.app/t/app-pro-tuya-cloud/21313</a></label>
39+
<label for="appid"><span data-i18n="settings.appid"></span></label>
40+
<label for="appid"></label><a target="_blank" href="https://community.homey.app/t/app-pro-tuya-cloud/21313">https://community.homey.app/t/app-pro-tuya-cloud/21313</a></label>
4041
<input id="appid" type="text" value="" />
4142
</div>
4243
<div class="field row">

util/logutil.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@ class LogUtil {
1414
log(...args) {
1515
this.logfunction(...args);
1616
}
17-
18-
logConnectionError(...args) {
19-
if(args.length > 0){
20-
this.lastConnectionError = args.join(';');
21-
}
22-
this.logfunction(...args);
23-
}
2417
}
2518

2619
module.exports = LogUtil;

0 commit comments

Comments
 (0)