Beispiel #1
0
    def test_BadTransitions(self):
        # initial state is false
        GPIO.input.return_value = False

        motionCallback = Mock()
        ms = MotionSensorRCWL0515(self.PIN, motionCallback)

        #Record GPIO callback method
        GPIOcallback = GPIO.add_event_detect.mock_calls[0][2]['callback']

        state_transition = [
            (1, True),  # Normal Transition
            (1, False),  # Warning Transition (events were lost)
            (0, True),  # Normal Transition
            (0, False),  # Warning Transition (events were lost)
        ]

        # Fake it .... till you make it ...
        for transition in state_transition:
            gpio_value = transition[0]
            should_call = transition[1]

            motionCallback.reset_mock()

            GPIO.input.return_value = gpio_value
            GPIOcallback(self.PIN)
            if should_call:
                motionCallback.assert_called()
            else:
                motionCallback.assert_not_called()
Beispiel #2
0
    def test_NormalTransitions(self):
        # initial state is false
        GPIO.input.return_value = False

        motionCallback = Mock()
        ms = MotionSensorRCWL0515(self.PIN, motionCallback)

        #Record GPIO callback method
        GPIOcallback = GPIO.add_event_detect.mock_calls[0][2]['callback']

        state_transition = [
            (1, True),
            (0, False),
            (1, True),
            (0, False),
        ]

        # Fake it .... till you make it ...
        for transition in state_transition:
            gpio_value = transition[0]
            next_state = transition[1]

            motionCallback.reset_mock()

            GPIO.input.return_value = gpio_value
            GPIOcallback(self.PIN)

            self.assertEqual(motionCallback.call_args.args[0].get_value(),
                             next_state)
Beispiel #3
0
    def probe(cls, send_payload_callback=None) -> list:
        """
        Probe for Bosch BME type sensors to the possible I2C addresses.

        Function which iterates over multiple I2C addresses and look for
        sensors of the type BoschBME. In case the sensor is not found at any
        of the specified I2C address, None is returned.
        """
        return [
            MotionSensorRCWL0515(gpio=cls.GPIO, callback=send_payload_callback)
        ]
    def test_GetState(self):
        cases = {
            (0, False),
            (1, True),
        }

        for case in cases:
            gpio_value = case[0]
            get_value = case[1]

            GPIO.input.return_value = gpio_value
            motionCallback = Mock()
            ms = MotionSensorRCWL0515(self.PIN, callback=motionCallback)

            self.assertEqual(ms.get(), get_value)
            ms.stop()
Beispiel #5
0
    def test_GetState(self):
        cases = {
            (0, False),
            (1, True),
        }

        for case in cases:
            gpio_value = case[0]
            get_value = case[1]

            GPIO.input.return_value = gpio_value
            motionCallback = Mock()
            ms = MotionSensorRCWL0515(self.PIN, motionCallback)
            #Record GPIO callback method
            GPIOcallback = GPIO.add_event_detect.mock_calls[0][2]['callback']

            self.assertEqual(ms.get(), get_value)