diff --git a/CHANGELOG.md b/CHANGELOG.md index a1b2cd5..63e202b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## 0.5.3 + +- [NEW] handle skipedIfSameStateActivities for POWER OFF in TV mode #104 - Just add "PowerOff" to the skipedIfSameStateActivities. + ## 0.5.2 - [FIX] ERROR - TVMODE - Override of a command throw an error if there is no device published in devicesToPublishAsAccessoriesSwitch #99 diff --git a/README.md b/README.md index 53a8591..84adbb4 100755 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Fields: - if you set to true, The "switch" will be "on" if and only if there is no current activity, and toggling it while "on" does nothing. - if you set to "inverted", The "switch" will be "off" if and only if there is no current activity, and toggling it while "off" does nothing. - if you set to "stateless", it will always be off, but can be triggered to switch off current activity. -- `skipedIfSameStateActivities` array of Activities name to trigger only if their state is different from the action sent. Can be usefull if your devices in the activity have the same on / off command and you want to automate them outside off the home app +- `skipedIfSameStateActivities` array of Activities name to trigger only if their state is different from the action sent. Can be usefull if your devices in the activity have the same on / off command and you want to automate them outside off the home app . For TV mode, and PowerOff feature, you can add "PowerOff" to this list if you want. - `addAllActivitiesToSkipedIfSameStateActivitiesList` option to add all activities automatically to skipedIfSameStateActivities behavior. (defaults : false) - `publishActivitiesAsIndividualAccessories` option to publish activities as individual accessories. Defaults to true. - `devicesToPublishAsAccessoriesSwitch` array of Devices to exposes with on/off function or custom functions @@ -78,6 +78,8 @@ Fields: - `playPauseBehavior` play/pause behavior in TV mode : if set to true, will send pause if played was set and vice-verca. Be aware that both commands must be available, and that it might be out of sync in case of external events (defaults : false - always send play command) - `remoteOverrideCommandsList` option to ovverride default commands mapping in TV Platform Mode. See below for format. +All devices / Activites names are the one configured in harmony configuration, even if you rename them in home app. + **Option** `devicesToPublishAsAccessoriesSwitch` is an array that behaves this way : - You should put the name of the device as it is named in harmony app, diff --git a/harmonyAsSwitches.js b/harmonyAsSwitches.js index a520153..8fa95a8 100644 --- a/harmonyAsSwitches.js +++ b/harmonyAsSwitches.js @@ -301,14 +301,6 @@ HarmonyPlatformAsSwitches.prototype = { }); }, - isActivtyToBeSkipped: function(activity) { - return ( - this.addAllActivitiesToSkipedIfSameStateActivitiesList || - (this.skipedIfSameStateActivities && - this.skipedIfSameStateActivities.includes(activity)) - ); - }, - setSwitchOnCharacteristic: function( homebridgeAccessory, characteristic, @@ -321,7 +313,9 @@ HarmonyPlatformAsSwitches.prototype = { let currentValue = characteristic.value; //Actitiy in skipedIfSameState - if (this.isActivtyToBeSkipped(service.controlService.subtype)) { + if ( + HarmonyTools.isActivtyToBeSkipped(this, service.controlService.subtype) + ) { this.log.debug( 'INFO : SET on an activty in skipedIfsameState list ' + service.controlService.subtype diff --git a/harmonyAsTVPlatform.js b/harmonyAsTVPlatform.js index 185b22a..01e1597 100644 --- a/harmonyAsTVPlatform.js +++ b/harmonyAsTVPlatform.js @@ -389,7 +389,8 @@ HarmonyPlatformAsTVPlatform.prototype = { let doCommand = true; let commandToSend = value; - let inputName = ''; + let inputName = commandToSend == -1 ? 'PowerOff' : ''; + for (let i = 0, len = this.inputServices.length; i < len; i++) { if (this.inputServices[i].activityId == commandToSend) { inputName = this.inputServices[i].activityName; @@ -397,16 +398,10 @@ HarmonyPlatformAsTVPlatform.prototype = { } } - if ( - this.addAllActivitiesToSkipedIfSameStateActivitiesList || - (this.skipedIfSameStateActivities && - this.skipedIfSameStateActivities.includes(inputName)) - ) { + if (HarmonyTools.isActivtyToBeSkipped(this, inputName)) { //GLOBAL OFF SWITCH : do command only if we are not off if (commandToSend == -1) { - doCommand = - this._currentActivity != -1 && - this._currentActivity > HarmonyConst.CURRENT_ACTIVITY_NOT_SET_VALUE; + doCommand = this._currentActivity > 0; } //ELSE, we do the command only if state is different. else { @@ -520,10 +515,6 @@ HarmonyPlatformAsTVPlatform.prototype = { }, HarmonyConst.DELAY_BETWEEN_ATTEMPS_STATUS_UPDATE); } }); - /* - .catch(e => { - this.log('ERROR - activityCommand : ' + e); - });*/ }, handlePlayPause: function() { diff --git a/harmonyTools.js b/harmonyTools.js index 47e08f2..4ccef9b 100644 --- a/harmonyTools.js +++ b/harmonyTools.js @@ -14,6 +14,14 @@ module.exports = { ); }, + isActivtyToBeSkipped: function(platform, activity) { + return ( + platform.addAllActivitiesToSkipedIfSameStateActivitiesList || + (platform.skipedIfSameStateActivities && + platform.skipedIfSameStateActivities.includes(activity)) + ); + }, + processCommands: async function(hb, platform, commands) { for (const command of commands) { let commandTosend = command.split('|'); diff --git a/package.json b/package.json index f8a1f15..d24f079 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homebridge-harmony", - "version": "0.5.2", + "version": "0.5.3", "author": "Nicolas Dujardin", "description": "Publish your harmony activities as homekit accessories", "main": "index.js",