Skip to content

Instantly share code, notes, and snippets.

@dlashua
Last active December 11, 2021 07:09
Show Gist options
  • Save dlashua/fedb4ff6186b0fb00b4240c19cfc4f3b to your computer and use it in GitHub Desktop.
Save dlashua/fedb4ff6186b0fb00b4240c19cfc4f3b to your computer and use it in GitHub Desktop.
a base app in AppDaemon
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
global_modules:
- base
myapp:
module: appmodule
class: MyApp
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