Skip to content

Commit

Permalink
allow user set the push interval as a callback function to get dynami…
Browse files Browse the repository at this point in the history
…c interval (#46)
  • Loading branch information
Ksoy authored Mar 15, 2021
1 parent f7772fd commit 780dc8f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion iottalkpy/dai.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def __init__(self, api_url, device_model, device_addr=None,
self.device_features = device_features if device_features else {}
self.flags = {}

def _get_interval(self, df_name):
interval = self.interval.get(df_name, self.push_interval)
return interval() if callable(interval) else interval

def push_data(self, df_name):
if not self.device_features[df_name].push_data:
return
Expand All @@ -72,7 +76,7 @@ def push_data(self, df_name):
_data = self.device_features[df_name].push_data()
if not isinstance(_data, NoData) and _data is not NoData:
self.dan.push(df_name, _data)
time.sleep(self.interval.get(df_name, self.push_interval))
time.sleep(self._get_interval(df_name))

def on_signal(self, signal, df_list):
log.info('Receive signal: \033[1;33m%s\033[0m, %s', signal, df_list)
Expand Down

0 comments on commit 780dc8f

Please sign in to comment.