Skip to content

Commit

Permalink
Merge pull request #1 from slametps/devel
Browse files Browse the repository at this point in the history
updated to new minor release
  • Loading branch information
slametps authored Sep 24, 2020
2 parents b6bcb40 + 36b143a commit af2c77b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MMM-TuyaSL Change Log

All notable changes will be documented in this file.

## [1.0.1] - 2020-09-24

## Updated
- round-robin the tuya domain to gain shorter update interval
- shortening default interval

## [1.0] - 2020-09-20

**Note:** This is an initial release.

### Added
- list all available devices in Tuya-IoT-Platform (managed by [SmartLife](https://play.google.com/store/apps/details?id=com.tuya.smartlife) app)
- display options (any states/online only/active only)
- save accessToken to file (reduce authentication activity)
- translations (id, en)
- telegram support (requires MMM-TelegramBot)
3 changes: 2 additions & 1 deletion MMM-TuyaSL.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Module.register("MMM-TuyaSL", {
start: function () {
var self = this;
var devices = [];
if (self.config.updateInterval < 300*1000) self.config.updateInterval = 300*1000; // minimal is 300*1000 ms
const DEFAULT_INTERVAL = 125;
if (self.config.updateInterval < DEFAULT_INTERVAL*1000) self.config.updateInterval = DEFAULT_INTERVAL*1000; // minimal is 300*1000 ms

//this.getLogin();
this.getData();
Expand Down
13 changes: 10 additions & 3 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ var arrDevices = [];
var arrDevicesItem;
var accessToken;
var loginDataResult = {success: false};
var regionTuya;

module.exports = NodeHelper.create({
// Subclass start method.
start: function() {
console.log("Starting node_helper.js for MMM-TuyaSL.");
regionTuya = 'eu';
},

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

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

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

if (res.data.header.code === 'SUCCESS') {
if ("header" in res.data && "code" in res.data.header && res.data.header.code === 'SUCCESS') {
try {
function myDeviceItem(value, index, array) {
deviceOnline = value.data.online;
//deviceOnline = (value.data.online === "false" ? false : value.data.online);
deviceState = (value.data.state == "true" ? true : (value.data.state == "false" ? false : value.data.state));
arrDevicesItem = {alias:value.name, type:value.dev_type, online:deviceOnline, on_off:deviceState};
arrDevices.push(arrDevicesItem);
}

res.data.payload.devices.forEach(myDeviceItem);
//console.log(`DEBUG: Number of Devices = ${arrDevices.length}`);
console.log(`DEBUG: Number of Devices = ${arrDevices.length}`);
//console.log(`DEBUG: Device-List ${that.dump(arrDevices)}`);
}
catch (e) {
Expand Down

0 comments on commit af2c77b

Please sign in to comment.