mirror of
				https://github.com/KevinMidboe/python-gpiozero.git
				synced 2025-10-29 17:50:37 +00:00 
			
		
		
		
	MockPin fixups
* alter the PinSetInput exception message to match other `Pin` implementations * constrain the state of MockPin to a `bool`, and the state of MockPWMPin to a `float` * allow MockPin to have a `None` frequency set, matching the docs http://gpiozero.readthedocs.org/en/latest/api_pins.html#gpiozero.pins.Pin.frequency
This commit is contained in:
		@@ -64,9 +64,10 @@ class MockPin(Pin):
 | 
			
		||||
 | 
			
		||||
    def _set_state(self, value):
 | 
			
		||||
        if self._function == 'input':
 | 
			
		||||
            raise PinSetInput()
 | 
			
		||||
            raise PinSetInput('cannot set state of pin %r' % self)
 | 
			
		||||
        assert self._function == 'output'
 | 
			
		||||
        assert 0 <= value <= 1
 | 
			
		||||
        value = bool(value)
 | 
			
		||||
        if self._state != value:
 | 
			
		||||
            t = time()
 | 
			
		||||
            self._state = value
 | 
			
		||||
@@ -77,7 +78,8 @@ class MockPin(Pin):
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
    def _set_frequency(self, value):
 | 
			
		||||
        raise PinPWMUnsupported()
 | 
			
		||||
        if value is not None:
 | 
			
		||||
            raise PinPWMUnsupported()
 | 
			
		||||
 | 
			
		||||
    def _get_pull(self):
 | 
			
		||||
        return self._pull
 | 
			
		||||
@@ -159,6 +161,18 @@ class MockPWMPin(MockPin):
 | 
			
		||||
        super(MockPWMPin, self).__init__(number)
 | 
			
		||||
        self._frequency = None
 | 
			
		||||
 | 
			
		||||
    def _set_state(self, value):
 | 
			
		||||
        if self._function == 'input':
 | 
			
		||||
            raise PinSetInput('cannot set state of pin %r' % self)
 | 
			
		||||
        assert self._function == 'output'
 | 
			
		||||
        assert 0 <= value <= 1
 | 
			
		||||
        value = float(value)
 | 
			
		||||
        if self._state != value:
 | 
			
		||||
            t = time()
 | 
			
		||||
            self._state = value
 | 
			
		||||
            self.states.append(PinState(t - self._last_change, value))
 | 
			
		||||
            self._last_change = t
 | 
			
		||||
 | 
			
		||||
    def _get_frequency(self):
 | 
			
		||||
        return self._frequency
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user