Example #1
0
 def __init__(self, topic, hardware_device, min_value=None, max_value=None):
     Notifier.__init__(self)
     Observer.__init__(self)
     DigitalDevice.__init__(self)
     MQTTTarget.__init__(self, topic=topic)
     self._hardware_device = hardware_device
     self._min_value = min_value
     self._max_value = max_value
     self._setup_hardware_device()
Example #2
0
 def __init__(self, size: int, hardware_device=None):
     logger.debug(
         'Creating a digital sensor group with {0} sensors'.format(size))
     Notifier.__init__(self)
     Observer.__init__(self)
     self._states = [DigitalSensor.LOW] * size
     self._hardware_device = hardware_device
     self._read_states_from_hardware_device()
     logger.debug(
         'Digital sensor group with {0} sensors is created'.format(size))
Example #3
0
 def __init__(self, channel: int):
     logger.debug('Creating a GPIO notifier at channel {0}'.format(channel))
     Notifier.__init__(self)
     with self._mutex:
         if len(self._gpios) == 0:
             GPIO.setmode(GPIO.BCM)
         if channel not in self._gpios:
             GPIO.setup(channel, GPIO.IN)
             GPIO.add_event_detect(channel, GPIO.BOTH, callback=self.callback_method, bouncetime=100)
             self._gpios.append(channel)
     logger.debug('GPIO notifier at channel {0} is created'.format(channel))
Example #4
0
 def __init__(self, topic, strategy, client=None, enabled=True, timeout=1):
     Notifier.__init__(self)
     MQTTObserver.__init__(self, topic=topic)
     self._enabled = enabled
     self._strategy = strategy
     self._is_alarm = False
     self._payload = None
     self._payload_changed_at = None
     self._timeout = timeout
     self._mutex = threading.Lock()
     if client is not None:
         client.register_observer(self)
Example #5
0
    def test_notify_observers(self):
        notifier = Notifier()

        observer1 = Mock(spec=Observer)
        observer2 = Mock(spec=Observer)

        notifier.register_observer(observer1)
        notifier.register_observer(observer2)

        notifier.notify_observers()

        observer1.notify.assert_called_once_with(notifier=notifier)
        observer2.notify.assert_called_once_with(notifier=notifier)
Example #6
0
 def __init__(self, topic: str, sensor_group, index: int):
     Notifier.__init__(self)
     Observer.__init__(self)
     DigitalDevice.__init__(self)
     MQTTTarget.__init__(self, topic=topic)
     logger.debug(
         'Creating a digital sensor named {0} at position {1} in the sensor group {2}'.format(self.topic, index,
                                                                                              sensor_group))
     # assert that the index exists in the device group
     sensor_group._get_state(index)
     sensor_group.register_observer(self)
     self._sensor_group = sensor_group
     self._index = index
     self._previous_state = None
     logger.debug(
         'Digital sensor named {0} at position {1} in the sensor group {2} is created'.format(self.topic, index,
                                                                                              sensor_group))
Example #7
0
 def __init__(self, id, host, username=None, password=None):
     logger.debug('Creating MQTT client')
     Notifier.__init__(self)
     Observer.__init__(self)
     self._last_known_payload = {}
     self._mutex = Lock()
     self._client_id = id
     self._client = mqtt.Client(client_id=self._client_id, clean_session=True, protocol=mqtt.MQTTv311)
     if username is not None:
         self._client.username_pw_set(username=username, password=password)
     self._client.on_message = self._on_message
     self._client.on_connect = self._on_connect
     self._client.will_set(topic='client/{0}'.format(self._client_id), payload=self.LOST_CONNECTION, qos=1)
     self._connected = False
     self._client.connect(host)
     self._client.loop_start()
     logger.debug('MQTT client is created')
     while not self._connected:
         pass
     logger.debug('MQTT client is connected')
Example #8
0
 def __init__(self, topic: str, hardware_device=None):
     Notifier.__init__(self)
     Observer.__init__(self)
     self._hardware_device = hardware_device
     self._setup_hardware_device()
     self.name = topic
Example #9
0
 def __init__(self):
     Notifier.__init__(self)
     self._watchdogs = []
Example #10
0
 def test_register_non_observer(self):
     notifier = Notifier()
     non_observer = Mock()
     notifier.register_observer(non_observer)
Example #11
0
 def __init__(self, interval=1):
     Notifier.__init__(self)
     self._interval = interval