I’m trying to make a clear structure to my appDaemon to easen future development and debugging, but I have many problems with auto reload of modules that has been changed.
My current structure is done this way:
apps.yaml
sensors:
module: sensors
class: sensors
analysis:
module: analysis
class: analysis
sensors.py
class Sens():
def __init__(self, parent: hass.Hass, name):
self.name = name
self.parent = parent
self.value = None
self.par.listen_state(self.getValue, name)
def getValue(self, sensor, state, prev, val, *a, **ka):
self.value = self.parse(val)
def get(self):
return self.value
def set(self, v):
self.parent.set_state(self.name, state=v)
...
class Actuator(Sens):
def set(self, v):
super(Actuator, self).set(v)
...
class Sensors(hass.Hass):
s = None
def initialize(self):
self.dehumidifier = Actuator(parent=self, name="switch.dehumidifier_switch")
self.humidity = Sens(parent=self, "sensor.relative_humidity")
sensors.s = self
self.call_service("app/restart", app="analysis", namespace="admin")
analysis.py
s : Sensors|None = None
class analysis(hass.Hass):
def initialize(self):
self.run_minutely(self.timed, datetime.time(0, 0, 0))
def timed(self, **kwargs):
global s
if Sensors.s is None:
return
s = Sensors.s
s.dehumidifier.set(s.humidity.get() > 70)
Since analysis.s is initialized on Sensors.s every cycle, when sensors.py changes analysy read the updated class.
Since I call the service app/restart, when i change sensors even analysis starts to point to the new object.
But i’m having problems, for example Actuator.set fails on super for a strange reason:
super(type, obj): obj must be an instance or subtype of type
Is there a way to keep all classes updated on every file change?
All problems disappears when I restart AD, but it’s slow.