Creating help classes

Hello,

I am trying to create python classes in Appdaemon for functionalities I use often but where the functionality needs to keep track of its history and its own variables. This is working fine. These classes are never initialised by Appdaemon as apps, rather other apps calls for these classes.

However I am wondering if it is possible to make classes as these get access to the Appdaemon api, so that I can use the Appdaemon api within these help-classes. If it is possible, does anyone have any example?

Perhaps just pass self to the Class?

class Helper:
 def __init__(self, api):   
     api.log("Hello from Helper class") 
     sun = api.get_state("sun.sun")
     api.log("The sun is " + sun)

Then from the appdaemon app:

import hassapi as hass
import helper

class HelpTest(hass.Hass):
  def initialize(self):
    Helper = helper.Helper(self) 
    self.log("done") 
1 Like

Thank you Tomas! That did the trick:-)