Skip to content

Commit

Permalink
Merge pull request #52 from alydersen/chore/revert_curtains
Browse files Browse the repository at this point in the history
Reverting back the curtain driver
  • Loading branch information
alydersen authored Dec 1, 2022
2 parents 4575828 + 1df22da commit 49138ef
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 46 deletions.
3 changes: 3 additions & 0 deletions .homeychangelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,8 @@
},
"1.0.7": {
"en": "Refactoring code to improve performance and future proofing"
},
"1.0.8": {
"en": "Reverting back curtain driver after previous bugfix"
}
}
2 changes: 1 addition & 1 deletion .homeycompose/app.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "com.github.alydersen.hdl-smartbus-homey",
"version": "1.0.7",
"version": "1.0.8",
"compatibility": ">=5.0.0",
"sdk": 3,
"name": {
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"_comment": "This file is generated. Please edit .homeycompose/app.json instead.",
"id": "com.github.alydersen.hdl-smartbus-homey",
"version": "1.0.7",
"version": "1.0.8",
"compatibility": ">=5.0.0",
"sdk": 3,
"name": {
Expand Down
92 changes: 51 additions & 41 deletions drivers/curtain/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,59 @@ class CurtainDriver extends Homey.Driver {
};
}

async updateValues(signal) {
if (signal.parse)
signal.data = signal.parse(signal.payload);

// Parse and check the incoming signal, return if missing or invalid
if (signal.data == undefined) return;

if (signal.code == 0xE3E4) {
// This signal contains all channels, we need to process it for every device
signal.data.curtains.forEach((crtn, index) => {
// Get the device from Homey, return if not found or error
let signature = this.homey.app.devSignChnld(signal.sender.id, crtn.number)
let homeyDevice = this.getDevice(signature);
if ( typeof homeyDevice === 'undefined' || homeyDevice instanceof Error ) return;

// Update status only to idle (when autostop is used)
if (signal.data.curtains[index].status == 0) {
homeyDevice.updateStatus(signal.data.curtains[index].status);
}
});
getDeviceFromSignal(signal, channel) {
let hdl_subnet = this.homey.settings.get("hdl_subnet");

} else {
// Get the device from Homey, return if not found or error
let signature = this.homey.app.devSignChnld(signal.sender.id, signal.data.curtain)
let homeyDevice = this.getDevice(signature);
if ( typeof homeyDevice === 'undefined' || homeyDevice instanceof Error ) return;
let deviceSignature = {
id: `${hdl_subnet}.${signal.sender.id}.${signal.data.channel || channel}`,
address: `${hdl_subnet}.${signal.sender.id}`,
channel: signal.data.channel || channel
};

return this.getDevice(deviceSignature);
}

async updateValues(signal) {
if (signal.parse)
signal.data = signal.parse(signal.payload);

switch (signal.code) {
case 0xE3E1:
device.updateStatus(signal.data.status);
break;

case 0xE3E3:
device.updateStatus(signal.data.status);
if (signal.data.duration != null) // in some cases duration is not in response
device.updateDuration(signal.data.duration);
break;

case 0xE801:
device.updateDuration(signal.data.duration);
break;
if (signal.data) {
if (signal.code == 0xE3E4) {
// This signal contains all channels, we need to process it for every device
signal.data.curtains.forEach((crtn, index) => {
let device = this.getDeviceFromSignal(signal, crtn.number);
if (typeof device !== 'undefined') {
if (device instanceof Error) return;

// Update status only to idle (when autostop is used)
if (signal.data.curtains[index].status == 0)
device.updateStatus(signal.data.curtains[index].status);
}
});

} else {
let device = this.getDeviceFromSignal(signal, signal.data.curtain);
if (typeof device !== 'undefined') {
if (device instanceof Error) return;

switch (signal.code) {
case 0xE3E1:
device.updateStatus(signal.data.status);
break;

case 0xE3E3:
device.updateStatus(signal.data.status);
if (signal.data.duration != null) // in some cases duration is not in response
device.updateDuration(signal.data.duration);
break;

case 0xE801:
device.updateDuration(signal.data.duration);
break;
}
}
}
}
}
}

async onPairListDevices() {
Expand Down Expand Up @@ -136,4 +146,4 @@ class CurtainDriver extends Homey.Driver {
}
}

module.exports = CurtainDriver;
module.exports = CurtainDriver;
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.github.alydersen.homey-smartbus",
"version": "1.0.7",
"version": "1.0.8",
"main": "app.js",
"devDependencies": {
"@types/homey": "npm:homey-apps-sdk-v3-types@^0.3.1"
Expand Down

0 comments on commit 49138ef

Please sign in to comment.