Run_daily arguments

Hello,

I’m trying to call run.daily for data from following list (taken from apps.yaml):

{'day': '10:00', 'morning': '7:00', 'night': '22:30', 'evening': '18:15'}

using interation:

  def initialize(self):

   for hour in self.args['timeofday']:

      time_list =  str(self.args['timeofday'][hour]).split(':')
      runtime = datetime.time(int(time_list[0]),int(time_list[1]),0)
      self.run_daily(self.run_daily_c, runtime)

  def run_daily_c(self):
      self.log("RUNDAILY: ")

It works however I need to pass “timeofday” to the calls.

Is there a chance to pass elements of my list to particular run_daily_c calls?

Something like (it doesn’t work of course):

 def initialize(self):
   self.run_daily(self.run_daily_c, runtime, hour)

  def run_daily_c(self, hour):
    self.log("RUNDAILY: " + hour)

?

Greetings, M

No, you would need to do the math yourself and create an appropriate python time object.

your callback is wrongly formatted to begin with.

it should be

  def run_daily_c(self, kwargs):

i think what you want is this:

  def initialize(self):

   for hour in self.args['timeofday']:

      time_list =  str(self.args['timeofday'][hour]).split(':')
      runtime = datetime.time(int(time_list[0]),int(time_list[1]),0)
      self.run_daily(self.run_daily_c, runtime,runtime=hour)

  def run_daily_c(self, kwargs):
      self.log("RUNDAILY: {}".format(kwargs[runtime]))
1 Like

Shouldn’t the last line be

self.log("RUNDAILY: {}".format(kwargs['runtime']))

(quotes around runtime)?

your right.
but i think that after 2.5 years the TS foud that out himself :wink:

Yes, but you know: https://xkcd.com/979/

2 Likes