KraigM / homebridge-harmonyhub

HomeBridge Plugin for Logitech Harmony Hub
182 stars 52 forks source link

Improve Transition Between Activities #131

Open huebs opened 6 years ago

huebs commented 6 years ago

I just learned about this project after reading about it in the recent AppleInsider tutorial.

I was particularly excited to see if this could provide a solution to a bug I reported to @Logitech nearly 6 months ago that they don't appear to be even attempting to fix. It has to do with the Hue integration they provide. When transitioning between activities, it first sets the new activity's start configuration then sets the previous activity's end configuration.

I was disappointed to find that controlling the Hue scenes through HomeKit Automations tied to the state changes of the Harmony Activities led to the same behavior described above. I then went looking into the source here and I think I found a way to fix this. You'd change the code here from:

ActivityAccessory.prototype._updateActivityState = function (currentActivity) {
    if (currentActivity == null) currentActivity = this._currentActivity;
    else this._currentActivity = currentActivity;
    _.forEach(this._getActivityServices(), function(service){
        var val = getServiceActivityId(service) == currentActivity;
        service.getCharacteristic(Characteristic.On).setValue(val, null, true);
    });
};

To:

ActivityAccessory.prototype._updateActivityState = function (currentActivity) {
    if (currentActivity == null) currentActivity = this._currentActivity;
    else this._currentActivity = currentActivity;
    var currentService = null;
    _.forEach(this._getActivityServices(), function (service) {
        if (getServiceActivityId(service) == currentActivity) currentService = service;
        else service.getCharacteristic(Characteristic.On).setValue(false, null, true);
    });
    if (currentService) currentService.getCharacteristic(Characteristic.On).setValue(true, null, true);
};

This would ensure that the previous activity will be turned off before the next activity is started.

Would you consider this a bug fix? Would you be interested in a PR if it works?

huebs commented 6 years ago

I just tested my fix. IT WORKS!!! You still get a little weird flash of the outgoing activity's off scene before the incoming activity's scene is set (I don't see a way around that) but it works.

I've created both a hotfix PR for the master branch and a feature PR for the develop branch.

huebs commented 6 years ago

I've done further testing and the fix works even better than expected. Not only do they transition correctly when switching using Home/Siri, they also work properly when activated by the Harmony Remote itself or when triggered by the official Harmony Alexa Skill!

brownad commented 6 years ago

đź‘Ť

Sent from my iPhone

On 7 Apr 2018, at 21:58, Ben Huebscher notifications@github.com wrote:

I've done further testing and the fix works even better than expected. Not only do they transitions correctly when switching using Home/Siri, they also work properly when activated by the Harmony Remote itself or when triggered by the official Harmony Alexa Skill!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.