From 607bfb3627c32937ca7e542e462053bbb124ee06 Mon Sep 17 00:00:00 2001
From: Andrew Bauer <zonexpertconsulting@outlook.com>
Date: Thu, 18 Jun 2020 07:49:49 -0500
Subject: [PATCH] move StateChange subclass to signals.py
---
ouimeaux/signals.py | 39 ++++++++++++++++++++++++++-
1 files changed, 26 insertions(+), 1 deletions(-)
diff --git a/ouimeaux/signals.py b/ouimeaux/signals.py
index b421aab..22547d2 100644
--- a/ouimeaux/signals.py
+++ b/ouimeaux/signals.py
@@ -1,4 +1,4 @@
-from pysignals import Signal, StateChange, receiver
+from pysignals import Signal, receiver
# Work around a bug in pysignals when in the interactive interpreter
import sys
@@ -6,6 +6,43 @@
if _main:
_main.__file__ = "__main__.py"
+class StateChange( Signal ):
+
+ def __init__(self, providing_args=None):
+ super(StateChange, self).__init__(providing_args)
+ self.sender_status = {}
+
+ def send(self, sender, **named):
+ """
+ Send signal from sender to all connected receivers *only if* the signal's
+ contents has changed.
+ If any receiver raises an error, the error propagates back through send,
+ terminating the dispatch loop, so it is quite possible to not have all
+ receivers called if a raises an error.
+ Arguments:
+ sender
+ The sender of the signal Either a specific object or None.
+ named
+ Named arguments which will be passed to receivers.
+ Returns a list of tuple pairs [(receiver, response), ... ].
+ """
+ responses = []
+ if not self.receivers:
+ return responses
+
+ sender_id = _make_id(sender)
+ if sender_id not in self.sender_status:
+ self.sender_status[sender_id] = {}
+
+ if self.sender_status[sender_id] == named:
+ return responses
+
+ self.sender_status[sender_id] = named
+
+ for receiver in self._live_receivers(sender_id):
+ response = receiver(signal=self, sender=sender, **named)
+ responses.append((receiver, response))
+ return responses
# Fires when a device responds to a broadcast
discovered = Signal(providing_args=["address", "headers"])