def test_add_event_callback_not_configured_for_input(): with patch("OPi.GPIO.sysfs"): GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.OUT) with pytest.raises(RuntimeError) as ex: GPIO.add_event_callback(23, None) assert str(ex.value) == "Channel 23 is configured for output"
def test_add_event_callback(): with patch("OPi.GPIO.sysfs"): GPIO.setmode(GPIO.BOARD) GPIO.setup(23, GPIO.IN) with patch("OPi.GPIO.event") as mock: GPIO.add_event_callback(23, None) mock.add_edge_callback(14, None)
def enable_rx(self): """Enable RX, set up GPIO and add event detection.""" if self.tx_enabled: _LOGGER.error("TX is enabled, not enabling RX") return False if not self.rx_enabled: self.rx_enabled = True GPIO.setup(self.gpio, GPIO.IN) GPIO.add_event_detect(self.gpio, GPIO.BOTH) GPIO.add_event_callback(self.gpio, self.rx_callback) _LOGGER.debug("RX enabled") return True