Skip to content

Commit af2c77b

Browse files
authored
Merge pull request #1 from slametps/devel
updated to new minor release
2 parents b6bcb40 + 36b143a commit af2c77b

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
MMM-TuyaSL Change Log
2+
3+
All notable changes will be documented in this file.
4+
5+
## [1.0.1] - 2020-09-24
6+
7+
## Updated
8+
- round-robin the tuya domain to gain shorter update interval
9+
- shortening default interval
10+
11+
## [1.0] - 2020-09-20
12+
13+
**Note:** This is an initial release.
14+
15+
### Added
16+
- list all available devices in Tuya-IoT-Platform (managed by [SmartLife](https://play.google.com/store/apps/details?id=com.tuya.smartlife) app)
17+
- display options (any states/online only/active only)
18+
- save accessToken to file (reduce authentication activity)
19+
- translations (id, en)
20+
- telegram support (requires MMM-TelegramBot)

MMM-TuyaSL.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ Module.register("MMM-TuyaSL", {
5656
start: function () {
5757
var self = this;
5858
var devices = [];
59-
if (self.config.updateInterval < 300*1000) self.config.updateInterval = 300*1000; // minimal is 300*1000 ms
59+
const DEFAULT_INTERVAL = 125;
60+
if (self.config.updateInterval < DEFAULT_INTERVAL*1000) self.config.updateInterval = DEFAULT_INTERVAL*1000; // minimal is 300*1000 ms
6061

6162
//this.getLogin();
6263
this.getData();

node_helper.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ var arrDevices = [];
1616
var arrDevicesItem;
1717
var accessToken;
1818
var loginDataResult = {success: false};
19+
var regionTuya;
1920

2021
module.exports = NodeHelper.create({
2122
// Subclass start method.
2223
start: function() {
2324
console.log("Starting node_helper.js for MMM-TuyaSL.");
25+
regionTuya = 'eu';
2426
},
2527

2628
dump: function(v, s) {
@@ -169,7 +171,11 @@ module.exports = NodeHelper.create({
169171
let params = '{"header": {"name": "Discovery", "namespace": "discovery", "payloadVersion": 1}, "payload": {"accessToken": "' + that.accessToken + '"}}';
170172

171173
try {
172-
let res = await axios.post('https://px1.tuyaeu.com/homeassistant/skill', params, configAx);
174+
let res = await axios.post('https://px1.tuya' + regionTuya + '.com/homeassistant/skill', params, configAx);
175+
console.log(`DEBUG: regionTuya : ${regionTuya}`);
176+
if (regionTuya == 'eu') regionTuya = 'us';
177+
else if (regionTuya == 'us') regionTuya = 'cn';
178+
else if (regionTuya == 'cn') regionTuya = 'eu';
173179

174180
//console.log(`DEBUG: Status code : ${res.status}`);
175181
//console.log(`DEBUG: Status text : ${res.statusText}`);
@@ -183,17 +189,18 @@ module.exports = NodeHelper.create({
183189
//console.log(`DEBUG: Data.code : ${res.data.header.code}`);
184190
//console.log(`DEBUG: Data.payloadVersion: ${res.data.header.payloadVersion}`);
185191

186-
if (res.data.header.code === 'SUCCESS') {
192+
if ("header" in res.data && "code" in res.data.header && res.data.header.code === 'SUCCESS') {
187193
try {
188194
function myDeviceItem(value, index, array) {
189195
deviceOnline = value.data.online;
196+
//deviceOnline = (value.data.online === "false" ? false : value.data.online);
190197
deviceState = (value.data.state == "true" ? true : (value.data.state == "false" ? false : value.data.state));
191198
arrDevicesItem = {alias:value.name, type:value.dev_type, online:deviceOnline, on_off:deviceState};
192199
arrDevices.push(arrDevicesItem);
193200
}
194201

195202
res.data.payload.devices.forEach(myDeviceItem);
196-
//console.log(`DEBUG: Number of Devices = ${arrDevices.length}`);
203+
console.log(`DEBUG: Number of Devices = ${arrDevices.length}`);
197204
//console.log(`DEBUG: Device-List ${that.dump(arrDevices)}`);
198205
}
199206
catch (e) {

0 commit comments

Comments
 (0)