def __init__(self, name, pin, action, reset_state=True): self.name = name self.pin = pin if action not in (Device.ACTION_PULSE, Device.ACTION_SWITCH): raise DeviceWrongAction("Wrong action selected") self.action = action if reset_state: gpio_commands.mode(pin=self.pin, set_mode="out") gpio_commands.write(pin=self.pin, value=0) # We assume that the initial state is "off". It is impossible to read # actual state as well as the state can be interfered by the physical # buttons (in case of "PULSE" switches). I will deal with that later. (FIXME) self.write_state(state=0)
def test_set_wrong_mode(self): with self.assertRaises(WrongMode): mode(pin=1, set_mode='wrong_mode')
def test_mode_0_in(self, mock_system): mode(pin=0, set_mode='in') mock_system.assert_called_with('gpio -g mode 0 in')
def test_mode_wrong_pin(self): with self.assertRaises(WrongPinNumber): mode(pin=26, set_mode='out')
def test_mode_1_out(self, mock_system): mode(pin=1, set_mode='out') mock_system.assert_called_with('gpio -g mode 1 out')