Created
September 2, 2019 16:40
-
-
Save dlashua/3ed4d6bdf93b5e7b8d4e6e6de19578a0 to your computer and use it in GitHub Desktop.
Dynamic App Dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class app(hass.Hass): | |
def initialize(self): | |
helper = self.get_app('helper') | |
helper.add_dependent(self.name) | |
self.log(helper.do_a_thing()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HelperApp(hass.Hass): | |
def initialize(self): | |
self.log('I only help') | |
self._dependents = [] | |
if self.name in self.config: | |
old_dependents = self.config[self.name] | |
for dep in old_dependents: | |
self.start_app(dep) | |
self.config[self.name] = [] | |
def do_a_thing(self): | |
self.log('I did a thing') | |
return "I did it" | |
def add_dependent(self, app): | |
self._dependents.append(app) | |
def terminate(self): | |
self.log('remembering my dependents') | |
self.config[self.name] = self._dependents | |
self.log('killing my dependents') | |
for dep in self._dependents: | |
self.stop_app(dep) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment