Skip to content

Commit

Permalink
1.0.5 version fix basic, 4ch
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxmudjon committed Jun 15, 2020
1 parent d3b88e2 commit 0e4340e
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 9 deletions.
125 changes: 123 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.maxmudjon.ewelink",
"version": "1.0.4",
"version": "1.0.5",
"compatibility": ">=2.2.0",
"sdk": 2,
"name": {
Expand Down Expand Up @@ -2419,5 +2419,126 @@
}
]
}
]
],
"flow": {
"actions": [
{
"id": "secondChannelOn",
"title": {
"en": "Second channel turn on"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "secondChannelOff",
"title": {
"en": "Second channel turn off"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "secondChannelToggle",
"title": {
"en": "Second channel turn on or off"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "threeChannelOn",
"title": {
"en": "Three channel turn on"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "threeChannelOff",
"title": {
"en": "Three channel turn off"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "threeChannelToggle",
"title": {
"en": "Three channel turn on or off"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "fourChannelOn",
"title": {
"en": "Four channel turn on"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "fourChannelOff",
"title": {
"en": "Four channel turn off"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
},
{
"id": "fourChannelToggle",
"title": {
"en": "Four channel turn on or off"
},
"args": [
{
"name": "device",
"type": "device",
"filter": "driver_id=sonoff-4ch-pro"
}
]
}
]
}
}
47 changes: 44 additions & 3 deletions drivers/sonoff-4ch-pro/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,30 @@ class Sonoff4CHPro extends Homey.Device {
this.log("Sonoff Basic has been inited");
this.driver = this.getDriver();
this.data = this.getData();
this.handleStateChange = this.handleStateChange.bind(this);
this.registerStateChangeListener();
this.registerChannelToggle("onoff");
this.registerChannelToggle("onoff.1");
this.registerChannelToggle("onoff.2");
this.registerChannelToggle("onoff.3");
this.saving = false;
const { actions } = this.driver;
this.registerToggleAction("onoff.1", actions.secondChannelOn);
this.registerToggleAction("onoff.1", actions.secondChannelOff);
this.registerToggleAction("onoff.1", actions.secondChannelToggle);
this.registerToggleAction("onoff.2", actions.threeChannelOn);
this.registerToggleAction("onoff.2", actions.threeChannelOff);
this.registerToggleAction("onoff.2", actions.threeChannelToggle);
this.registerToggleAction("onoff.3", actions.fourChannelOn);
this.registerToggleAction("onoff.3", actions.fourChannelOff);
this.registerToggleAction("onoff.3", actions.fourChannelToggle);
}

handleStateChange(device) {
console.log("TCL: Sonoff4CHPro -> handleStateChange -> device", device);
if (device.params) {
if (device.params.switch == "on") this.updateCapabilityValue("onoff", true);
if (device.params.switch == "off") this.updateCapabilityValue("onoff", false);

if (device.params.startup && !this.saving)
this.setSettings({
powerResponse: device.params.startup
Expand Down Expand Up @@ -109,12 +120,42 @@ class Sonoff4CHPro extends Homey.Device {
});
}

registerToggleAction(name, action) {
action.registerRunListener(async (args, state) => {
let channels = [{ outlet: 0, switch: "on" }, { outlet: 1, switch: "on" }, { outlet: 2, switch: "on" }, { outlet: 3, switch: "on" }];
if (name == "onoff") {
channels[0].switch = value ? "on" : "off";
channels[1].switch = args.device.getCapabilityValue("onoff.1") ? "on" : "off";
channels[2].switch = args.device.getCapabilityValue("onoff.2") ? "on" : "off";
channels[3].switch = args.device.getCapabilityValue("onoff.3") ? "on" : "off";
} else if (name == "onoff.1") {
channels[0].switch = args.device.getCapabilityValue("onoff") ? "on" : "off";
channels[1].switch = value ? "on" : "off";
channels[2].switch = args.device.getCapabilityValue("onoff.2") ? "on" : "off";
channels[3].switch = args.device.getCapabilityValue("onoff.3") ? "on" : "off";
} else if (name == "onoff.2") {
channels[0].switch = args.device.getCapabilityValue("onoff") ? "on" : "off";
channels[1].switch = args.device.getCapabilityValue("onoff.1") ? "on" : "off";
channels[2].switch = value ? "on" : "off";
channels[3].switch = args.device.getCapabilityValue("onoff.3") ? "on" : "off";
} else if (name == "onoff.3") {
channels[0].switch = args.device.getCapabilityValue("onoff") ? "on" : "off";
channels[1].switch = args.device.getCapabilityValue("onoff.1") ? "on" : "off";
channels[2].switch = args.device.getCapabilityValue("onoff.2") ? "on" : "off";
channels[3].switch = value ? "on" : "off";
}

Homey.app.ewelinkApi.setPower2State(data, channels);
return true;
});
}

registerStateChangeListener() {
Homey.app.ewelinkApi.on(this.data.deviceid, event => this.handleStateChange(event));
Homey.app.ewelinkApi.on(this.data.deviceid, this.handleStateChange);
}

unregisterStateChangeListener() {
Homey.app.ewelinkApi.removeListener(this.data.deviceid, event => this.handleStateChange(event));
Homey.app.ewelinkApi.removeListener(this.data.deviceid, this.handleStateChange);
}

onDeleted() {
Expand Down
14 changes: 14 additions & 0 deletions drivers/sonoff-4ch-pro/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ const Homey = require("homey");
const models = ["4CH Pro"];

class Sonoff4CHPro extends Homey.Driver {
onInit() {
this.actions = {
secondChannelOn: new Homey.FlowCardAction("secondChannelOn").register(),
secondChannelOff: new Homey.FlowCardAction("secondChannelOff").register(),
secondChannelToggle: new Homey.FlowCardAction("secondChannelToggle").register(),
threeChannelOn: new Homey.FlowCardAction("threeChannelOn").register(),
threeChannelOff: new Homey.FlowCardAction("threeChannelOff").register(),
threeChannelToggle: new Homey.FlowCardAction("threeChannelToggle").register(),
fourChannelOn: new Homey.FlowCardAction("fourChannelOn").register(),
fourChannelOff: new Homey.FlowCardAction("fourChannelOff").register(),
fourChannelToggle: new Homey.FlowCardAction("fourChannelToggle").register()
};
}

async onPairListDevices(data, callback) {
await Homey.app.ewelinkApi
.getDevices()
Expand Down
1 change: 1 addition & 0 deletions drivers/sonoff-basic/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Homey = require("homey");
class SonoffBasic extends Homey.Device {
onInit() {
this.log("Sonoff Basic has been inited");
this.handleStateChange = this.handleStateChange.bind(this);
this.driver = this.getDriver();
this.data = this.getData();
this.registerStateChangeListener();
Expand Down
6 changes: 3 additions & 3 deletions drivers/sonoff-t4-1c/device.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class SonoffT41C extends Homey.Device {
this.log("Sonoff Basic has been inited");
this.driver = this.getDriver();
this.data = this.getData();
this.handleStateChange = this.handleStateChange.bind(this);
this.registerStateChangeListener();
this.registerToggle("onoff");
this.saving = false;
}

handleStateChange(device) {
console.log("[INFO]: SonoffT41C -> handleStateChange -> device", device);
if (device.params) {
if (device.params.switch == "on") this.updateCapabilityValue("onoff", true);
if (device.params.switch == "off") this.updateCapabilityValue("onoff", false);
Expand Down Expand Up @@ -70,11 +70,11 @@ class SonoffT41C extends Homey.Device {
}

registerStateChangeListener() {
Homey.app.ewelinkApi.on(this.data.deviceid, event => this.handleStateChange(event));
Homey.app.ewelinkApi.on(this.data.deviceid, this.handleStateChange);
}

unregisterStateChangeListener() {
Homey.app.ewelinkApi.removeListener(this.data.deviceid, event => this.handleStateChange(event));
Homey.app.ewelinkApi.removeListener(this.data.deviceid, this.handleStateChange);
}

onDeleted() {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.maxmudjon.ewelink",
"version": "1.0.4",
"version": "1.0.5",
"description": "ewelink",
"main": "app.js",
"dependencies": {
Expand Down

0 comments on commit 0e4340e

Please sign in to comment.