From d04e9ba0700b2ec0b87a9b234087c2406597ea36 Mon Sep 17 00:00:00 2001 From: Neverhorst Date: Fri, 18 Dec 2020 19:58:45 +0100 Subject: [PATCH 1/2] Fixed a bug in the switch interface caused by decorating not only the property but also the setter function as abstractmethod. Removed explicit states property declaration from dummy module to showcase the working change. Fixed a bug in the switch logic causing the watchdog to not register switch state changes. --- hardware/switches/switch_dummy.py | 23 ----------------------- interface/switch_interface.py | 4 ++-- logic/switch_logic.py | 5 +++-- 3 files changed, 5 insertions(+), 27 deletions(-) diff --git a/hardware/switches/switch_dummy.py b/hardware/switches/switch_dummy.py index 3d4eac08eb..93a5217c2f 100644 --- a/hardware/switches/switch_dummy.py +++ b/hardware/switches/switch_dummy.py @@ -91,29 +91,6 @@ def available_states(self): """ return self._switches.copy() - @property - def states(self): - """ The current states the hardware is in as state dictionary with switch names as keys and - state names as values. - - @return dict: All the current states of the switches in the form {"switch": "state"} - """ - return self._states.copy() - - @states.setter - def states(self, state_dict): - """ The setter for the states of the hardware. - - The states of the system can be set by specifying a dict that has the switch names as keys - and the names of the states as values. - - @param dict state_dict: state dict of the form {"switch": "state"} - """ - assert isinstance(state_dict, dict), \ - f'Property "state" must be dict type. Received: {type(state_dict)}' - for switch, state in state_dict.items(): - self.set_state(switch, state) - def get_state(self, switch): """ Query state of single switch by name diff --git a/interface/switch_interface.py b/interface/switch_interface.py index ed847515a6..40f6554c3c 100644 --- a/interface/switch_interface.py +++ b/interface/switch_interface.py @@ -101,7 +101,6 @@ def states(self): return {switch: self.get_state(switch) for switch in self.available_states} @states.setter - @interface_method def states(self, state_dict): """ The setter for the states of the hardware. @@ -110,7 +109,8 @@ def states(self, state_dict): @param dict state_dict: state dict of the form {"switch": "state"} """ - assert isinstance(state_dict), 'Parameter "state_dict" must be dict type' + print(state_dict) + assert isinstance(state_dict, dict), 'Parameter "state_dict" must be dict type' for switch, state in state_dict.items(): self.set_state(switch, state) diff --git a/logic/switch_logic.py b/logic/switch_logic.py index ae325d8cdb..aef83eda94 100644 --- a/logic/switch_logic.py +++ b/logic/switch_logic.py @@ -105,7 +105,6 @@ def states(self): with self._thread_lock: try: states = self.switch().states - self._old_states = states except: self.log.exception(f'Error during query of all switch states.') states = dict() @@ -139,7 +138,6 @@ def get_state(self, switch): with self._thread_lock: try: state = self.switch().get_state(switch) - self._old_states[switch] = state except: self.log.exception(f'Error while trying to query state of switch "{switch}".') state = None @@ -194,5 +192,8 @@ def _watchdog_body(self): state != self._old_states[switch]} self._old_states = curr_states if diff_state: + print('state_changed', diff_state) self.sigSwitchesChanged.emit(diff_state) + else: + print('Nope') QtCore.QTimer.singleShot(self._watchdog_interval_ms, self._watchdog_body) From d5db662755e366cdfe33d2ea4bf176af42eb3203 Mon Sep 17 00:00:00 2001 From: Jan Binder Date: Tue, 22 Dec 2020 09:16:43 +0100 Subject: [PATCH 2/2] got rid of the prints --- interface/switch_interface.py | 1 - logic/switch_logic.py | 3 --- 2 files changed, 4 deletions(-) diff --git a/interface/switch_interface.py b/interface/switch_interface.py index 40f6554c3c..a4e3cb0c9d 100644 --- a/interface/switch_interface.py +++ b/interface/switch_interface.py @@ -109,7 +109,6 @@ def states(self, state_dict): @param dict state_dict: state dict of the form {"switch": "state"} """ - print(state_dict) assert isinstance(state_dict, dict), 'Parameter "state_dict" must be dict type' for switch, state in state_dict.items(): self.set_state(switch, state) diff --git a/logic/switch_logic.py b/logic/switch_logic.py index aef83eda94..d22c63225c 100644 --- a/logic/switch_logic.py +++ b/logic/switch_logic.py @@ -192,8 +192,5 @@ def _watchdog_body(self): state != self._old_states[switch]} self._old_states = curr_states if diff_state: - print('state_changed', diff_state) self.sigSwitchesChanged.emit(diff_state) - else: - print('Nope') QtCore.QTimer.singleShot(self._watchdog_interval_ms, self._watchdog_body)