Appdaemon datetime

The following snippet of code is driving me nutz. More to the point, the datatime functions of appdaemon are driving me nutz.
Run_every says it needs a datetime object. I’m trying to use the appdaemon datetime functionality to support timetravel if I ever have a reason to use it. I’ve tried it with datetime imported, with datetime and time imported, and with neither of them imported. Explain the magic please.

self.log("about to set time")
time=self.datetime()
self.log("time={}".format(time))
self.run_every(self.timer_handler,time,3*60)
self.log("event scheduled")
#self.check_battery_state()
#self.log("back from check battery state")

  def timer_handler(self,**kwargs):
self.check_battery_state()

Log looks like this

2017-05-10 14:54:04.279845 INFO Loading Object battery_control using class battery_control from module battery_control
2017-05-10 14:54:04.286075 INFO battery_control: initialize - (7) battery_control App
2017-05-10 14:54:04.291926 INFO battery_control: initialize - (17) about to set time
2017-05-10 14:54:04.297816 INFO battery_control: initialize - (19) time=2017-05-10 14:54:05
2017-05-10 14:54:04.304055 INFO battery_control: initialize - (21) event scheduled
2017-05-10 14:54:04.314077 WARNING Logged an error to /home/homeassistant/appdaemon/appdaemon.err

Error log looks like this

2017-05-10 15:00:05.168395 WARNING ------------------------------------------------------------
2017-05-10 15:03:05.167695 WARNING ------------------------------------------------------------
2017-05-10 15:03:05.168551 WARNING Unexpected error in worker for App battery_control:
2017-05-10 15:03:05.169254 WARNING Worker Ags: {'id': UUID('47bb79e0-d7e1-461d-9aec-b842c1b062cd'), 'kwargs': {'interval': 180}, 'function': <bound method battery_control.timer_handler of <battery_control.battery_control object at 0x706ab770>>, 'name': 'battery_control', 'type': 'timer'}
2017-05-10 15:03:05.169835 WARNING ------------------------------------------------------------
2017-05-10 15:03:05.170644 WARNING Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/appdaemon/appdaemon.py", line 602, in worker
    function(ha.sanitize_timer_kwargs(args["kwargs"]))
TypeError: timer_handler() takes 1 positional argument but 2 were given

2017-05-10 15:03:05.171240 WARNING ------------------------------------------------------------

self.run_every(self.timer_handler,time,“3*60”)

hmm, according to the docs should an int work.
but this should be your problem:

def timer_handler(self,**kwargs):

should be

def timer_handler(self,kwargs):

Yes, this is most likely the problem.

1 Like

Yes that was it. Sometimes you need it “**” sometimes you don’t.

1 Like