Skip to content
This repository has been archived by the owner on Dec 27, 2019. It is now read-only.

Commit

Permalink
Add flow cards for changes in TV status
Browse files Browse the repository at this point in the history
  • Loading branch information
casperboone committed Feb 11, 2017
1 parent e92d1a6 commit 3d61639
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 133 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ After adding your TV to your devices, you will get flow cards for:
* Set your TV to a different channel
* Power off
* Change volume / mute
* Changes in power status (if and when cards)

There's much more possible, but I only included the most used actions. If you miss anything, feel free to open an issue or [contact me](#contact-me) directly.

Expand Down
22 changes: 20 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,19 @@ const self = module.exports = {
callback("TV offline");
});
});

/**
* CONDITION: TV is on
*/
Homey.manager('flow').on('condition.tv_is_available', (callback, args) => {
deviceAvailable(args.tv.ip, result => {
if (result) {
callback(null, true);
return;
}
callback(null, false);
});
});
},

addDevice(ip, callback) {
Expand Down Expand Up @@ -236,17 +249,22 @@ function deviceUpdateAvailability(ip, callback) {
if (err) {
Homey.log("DUA:step1.5");

tv.available = false;
Homey.manager('drivers').getDriver('tv').setUnavailable({id: ip, ip: ip});
if (tv.available) {
tv.available = false;
Homey.manager('drivers').getDriver('tv').setUnavailable({id: ip, ip: ip});
Homey.manager('flow').triggerDevice('tv_became_unavailable', {}, {}, {id: ip, ip: ip});
}

callback(false);
return;
}
Homey.log("DUA:step2");
if (!tv.available) {
Homey.log("DUA:step3");

tv.available = true;
Homey.manager('drivers').getDriver('tv').setAvailable({id: ip, ip: ip});
Homey.manager('flow').triggerDevice('tv_became_available', {}, {}, {id: ip, ip: ip});

// Set remote, smp2 and soap api instance
tv.remote = new SamsungTVRemote(ip);
Expand Down
Loading

0 comments on commit 3d61639

Please sign in to comment.