def subscribe(self, points, stream, startdatetime=None, enddatetime=None, callback=None):
"""Monitor whenever the PI point is read and an update has occurred.
Trigger the callback function when the value changes
:param Points points: List of Point objects to start monitoring
:param string stream: Name of the reading method used for monitoring the point.
Options are current, interpolatedattimes, recordedattime, end
:param string startdatetime: Optional – Timestamp for when to start monitoring
:param string enddatetime: Optional – Timestamp for when to stop monitoring
:param func callback: Reference to the function to trigger when an update occurs
"""
if not isinstance(points, Points):
raise TypeError('The object "{}" is not of type "{}"'.format(
points, Points))
for p in points:
formattedstartdate = self._parse_timestamp(startdatetime)
formattedenddate = self._parse_timestamp(enddatetime)
signalkey = '{}/{}/{}{}'.format(p.webid.__str__(), stream, formattedstartdate or '', formattedenddate or '')
if signalkey not in self.signals:
s = blinker.signal(signalkey)
self.signals[signalkey] = s
if callback:
self.signals[signalkey].connect(callback)
return self.signals
评论列表
文章目录