OHService.onUpdate

Could OHService.onUpdate return the handler to allow for deregistration? Use case:

var someHandler = undefined;
$scope.$watch(someVar, function(newValue, oldValue) {
   if (handler != undefined) {
      handler();
   }
   somHandler = OHService.onUpdate("mychannel" + newValue, function() { doSomething; });
});

Basically I need to subscribe/unsubscribe from channel updates based on another variable. After looking at the onUpdate method (of openhab.service.js) - looks like that handler is never returned. Without returning the handler, I’d have to do something icky (like using $$listeners).

Please let me know if I missed something (still new to angularjs)…

Second question - how do I access “config” in a custom controller?

Sure, but this function is only there for compatibility reasons with the original widgets anyway.

You can simply subscribe to the event in your controllers instead.

var handler = $rootScope.$on('openhab-update', callback);
$scope.$on('$destroy', handler);

how do I access “config” in a custom controller?

It should be in the scope - so $scope.config.

Yeah - I contemplated just doing that directly - wasn’t sure if you wanted to expose the ‘innards’ like that or not.

$scope.config was not in the scope nor any of the parent scopes either (neither was any of the other helper methods - like itemValue, etc) and I’m really not sure why it wasn’t. Started to dive through all of the code but it’s beyond my ‘angularjs’ knowledge at this point.

BTW - this whole project rocks! Defining my own controller has absolutely worked and is fantastic!

Don’t know, maybe you’re accessing it too early. It should be set at some point.

Glad to hear that, be sure to share screenshots when you have something nice to show - always curious to see interesting things done with it! :slight_smile:

1 Like

Always is null for me.

EDIT: my $watch had an error in it. Just corrected and the $watcher does eventually kick off with a non-undefined $scope.config. I must somehow just be beating it being set. Think I’m good now.

BTW - main window screen shot below of one of the zones that’s set to streaming pandora. Have about 10 screen built so far (am/fm tuner screen, selecting of sources, management of favorites, management of presets, etc). About to create the ‘dynamic’ screens (russound has media management where we can create dynamic screens to manage the various sources).

2 Likes