1
0
mirror of https://github.com/JoelBender/bacpypes synced 2025-09-28 22:15:23 +08:00

add a generator for easier access to active subscriptions

This commit is contained in:
Joel Bender 2018-06-29 20:11:08 -04:00
parent 62decf7611
commit 463b2ec895
6 changed files with 142 additions and 117 deletions

View File

@ -444,9 +444,8 @@ class ActiveCOVSubscriptions(Property):
# start with an empty sequence
cov_subscriptions = ListOf(COVSubscription)()
# loop through the object and detection list
for obj, cov_detection in obj._app.cov_detections.items():
for cov in cov_detection.cov_subscriptions:
# loop through the subscriptions
for cov in obj._app.subscriptions():
# calculate time remaining
if not cov.lifetime:
time_remaining = 0
@ -544,6 +543,19 @@ class ChangeOfValueServices(Capability):
# delete it from the object map
del self.cov_detections[cov.obj_ref]
def subscriptions(self):
"""Generator for the active subscriptions."""
if _debug: ChangeOfValueServices._debug("subscriptions")
subscription_list = []
# loop through the object and detection list
for obj, cov_detection in self.cov_detections.items():
for cov in cov_detection.cov_subscriptions:
subscription_list.append(cov)
return subscription_list
def cov_notification(self, cov, request):
if _debug: ChangeOfValueServices._debug("cov_notification %s %s", str(cov), str(request))

View File

@ -37,7 +37,6 @@ class DetectionMonitor:
# if the algorithm is already triggered, don't bother checking for more
if self.algorithm._triggered:
if _debug: DetectionMonitor._debug(" - already triggered")
self.algorithm._triggered = False
return
# if there is a special filter, use it, otherwise use !=

View File

@ -442,9 +442,8 @@ class ActiveCOVSubscriptions(Property):
# start with an empty sequence
cov_subscriptions = ListOf(COVSubscription)()
# loop through the object and detection list
for obj, cov_detection in obj._app.cov_detections.items():
for cov in cov_detection.cov_subscriptions:
# loop through the subscriptions
for cov in obj._app.subscriptions():
# calculate time remaining
if not cov.lifetime:
time_remaining = 0
@ -541,6 +540,15 @@ class ChangeOfValueServices(Capability):
# delete it from the object map
del self.cov_detections[cov.obj_ref]
def subscriptions(self):
"""Generator for the active subscriptions."""
if _debug: ChangeOfValueServices._debug("subscriptions")
# loop through the object and detection list
for obj, cov_detection in self.cov_detections.items():
for cov in cov_detection.cov_subscriptions:
yield cov
def cov_notification(self, cov, request):
if _debug: ChangeOfValueServices._debug("cov_notification %s %s", str(cov), str(request))

View File

@ -38,7 +38,6 @@ class DetectionMonitor:
# if the algorithm is already triggered, don't bother checking for more
if self.algorithm._triggered:
if _debug: DetectionMonitor._debug(" - already triggered")
self.algorithm._triggered = False
return
# if there is a special filter, use it, otherwise use !=

View File

@ -442,9 +442,8 @@ class ActiveCOVSubscriptions(Property):
# start with an empty sequence
cov_subscriptions = ListOf(COVSubscription)()
# loop through the object and detection list
for obj, cov_detection in obj._app.cov_detections.items():
for cov in cov_detection.cov_subscriptions:
# loop through the subscriptions
for cov in obj._app.subscriptions():
# calculate time remaining
if not cov.lifetime:
time_remaining = 0
@ -541,6 +540,15 @@ class ChangeOfValueServices(Capability):
# delete it from the object map
del self.cov_detections[cov.obj_ref]
def subscriptions(self):
"""Generator for the active subscriptions."""
if _debug: ChangeOfValueServices._debug("subscriptions")
# loop through the object and detection list
for obj, cov_detection in self.cov_detections.items():
for cov in cov_detection.cov_subscriptions:
yield cov
def cov_notification(self, cov, request):
if _debug: ChangeOfValueServices._debug("cov_notification %s %s", str(cov), str(request))

View File

@ -38,7 +38,6 @@ class DetectionMonitor:
# if the algorithm is already triggered, don't bother checking for more
if self.algorithm._triggered:
if _debug: DetectionMonitor._debug(" - already triggered")
self.algorithm._triggered = False
return
# if there is a special filter, use it, otherwise use !=