Last active
December 11, 2021 07:09
-
-
Save dlashua/fedb4ff6186b0fb00b4240c19cfc4f3b to your computer and use it in GitHub Desktop.
a base app in AppDaemon
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
import appdaemon.plugins.hass.hassapi as hass | |
import base | |
class MyApp(hass.Hass): | |
def initialize(self): | |
self.depends_on_module(base) | |
base.App(self) | |
res = self.something() | |
self.log(res) # logs "thing" from base.py |
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
global_modules: | |
- base | |
myapp: | |
module: appmodule | |
class: MyApp |
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(object): | |
def __init__(self, app): | |
self.app = app | |
self.extend() | |
def add_to_app(self, fn): | |
fn_name = fn.__name__ | |
setattr(self.app, fn_name, types.MethodType(fn, self.app)) | |
return None | |
def extend(self): | |
@self.add_to_app | |
def something(self): | |
return "thing" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment