LINT fixes

This commit is contained in:
Fabio Manganiello 2019-12-22 18:14:42 +01:00
parent a23f5446da
commit 55d3f379d4

View file

@ -43,13 +43,13 @@ class GpioPlugin(Plugin):
for (name, number) in self.pins_by_name.items()} for (name, number) in self.pins_by_name.items()}
def _init_board(self): def _init_board(self):
import RPi.GPIO as gpio import RPi.GPIO as GPIO
with self._init_lock: with self._init_lock:
if self._initialized: if self._initialized:
return return
gpio.setmode(self.mode) GPIO.setmode(self.mode)
self._initialized = True self._initialized = True
def _get_pin_number(self, pin): def _get_pin_number(self, pin):
@ -64,15 +64,15 @@ class GpioPlugin(Plugin):
@staticmethod @staticmethod
def _get_mode(mode_str: str) -> int: def _get_mode(mode_str: str) -> int:
import RPi.GPIO as gpio import RPi.GPIO as GPIO
mode_str = mode_str.upper() mode_str = mode_str.upper()
assert mode_str in ['BOARD', 'BCM'], 'Invalid mode: {}'.format(mode_str) assert mode_str in ['BOARD', 'BCM'], 'Invalid mode: {}'.format(mode_str)
return getattr(gpio, mode_str) return getattr(GPIO, mode_str)
@action @action
def write(self, pin: Union[int, str], value: Union[int, bool], def write(self, pin: Union[int, str], value: Union[int, bool],
name: Optional[str] = None) -> Dict[str, Any]: name: Optional[str] = None) -> Dict[str, Any]:
""" """
Write a byte value to a pin. Write a byte value to a pin.
@ -90,18 +90,18 @@ class GpioPlugin(Plugin):
} }
""" """
import RPi.GPIO as gpio import RPi.GPIO as GPIO
self._init_board() self._init_board()
name = name or pin name = name or pin
pin = self._get_pin_number(pin) pin = self._get_pin_number(pin)
if pin not in self._initialized_pins or self._initialized_pins[pin] != gpio.OUT: if pin not in self._initialized_pins or self._initialized_pins[pin] != GPIO.OUT:
gpio.setup(pin, gpio.OUT) GPIO.setup(pin, GPIO.OUT)
self._initialized_pins[pin] = gpio.OUT self._initialized_pins[pin] = GPIO.OUT
gpio.setup(pin, gpio.OUT) GPIO.setup(pin, GPIO.OUT)
gpio.output(pin, value) GPIO.output(pin, value)
return { return {
'name': name, 'name': name,
@ -128,17 +128,17 @@ class GpioPlugin(Plugin):
} }
""" """
import RPi.GPIO as gpio import RPi.GPIO as GPIO
self._init_board() self._init_board()
name = name or pin name = name or pin
pin = self._get_pin_number(pin) pin = self._get_pin_number(pin)
if pin not in self._initialized_pins: if pin not in self._initialized_pins:
gpio.setup(pin, gpio.IN) GPIO.setup(pin, GPIO.IN)
self._initialized_pins[pin] = gpio.IN self._initialized_pins[pin] = GPIO.IN
val = gpio.input(pin) val = GPIO.input(pin)
return { return {
'name': name, 'name': name,
@ -165,6 +165,7 @@ class GpioPlugin(Plugin):
values = [] values = []
for (pin, name) in self.pins_by_number.items(): for (pin, name) in self.pins_by_number.items():
# noinspection PyUnresolvedReferences
values.append(self.read(pin=pin, name=name).output) values.append(self.read(pin=pin, name=name).output)
return values return values
@ -174,8 +175,8 @@ class GpioPlugin(Plugin):
""" """
Cleanup the state of the GPIO and resets PIN values. Cleanup the state of the GPIO and resets PIN values.
""" """
import RPi.GPIO as gpio import RPi.GPIO as GPIO
gpio.cleanup() GPIO.cleanup()
self._initialized_pins = {} self._initialized_pins = {}
self._initialized = False self._initialized = False