mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
ps - fix RPi GPIO imports
This commit is contained in:
parent
54060f27ef
commit
6dc2501116
@ -8,10 +8,6 @@ https://home-assistant.io/components/rpi_gpio/
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
try:
|
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
except ImportError:
|
|
||||||
GPIO = None
|
|
||||||
from homeassistant.const import (EVENT_HOMEASSISTANT_START,
|
from homeassistant.const import (EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP)
|
EVENT_HOMEASSISTANT_STOP)
|
||||||
REQUIREMENTS = ['RPi.GPIO==0.6.1']
|
REQUIREMENTS = ['RPi.GPIO==0.6.1']
|
||||||
@ -22,9 +18,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Sets up the Raspberry PI GPIO component. """
|
""" Sets up the Raspberry PI GPIO component. """
|
||||||
if GPIO is None:
|
import RPi.GPIO as GPIO
|
||||||
_LOGGER.error('RPi.GPIO not available. rpi_gpio ports ignored.')
|
|
||||||
return False
|
|
||||||
|
|
||||||
def cleanup_gpio(event):
|
def cleanup_gpio(event):
|
||||||
""" Stuff to do before stop home assistant. """
|
""" Stuff to do before stop home assistant. """
|
||||||
@ -41,27 +35,32 @@ def setup(hass, config):
|
|||||||
|
|
||||||
def setup_output(port):
|
def setup_output(port):
|
||||||
""" Setup a GPIO as output. """
|
""" Setup a GPIO as output. """
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
GPIO.setup(port, GPIO.OUT)
|
GPIO.setup(port, GPIO.OUT)
|
||||||
|
|
||||||
|
|
||||||
def setup_input(port, pull_mode):
|
def setup_input(port, pull_mode):
|
||||||
""" Setup a GPIO as input. """
|
""" Setup a GPIO as input. """
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
GPIO.setup(port, GPIO.IN,
|
GPIO.setup(port, GPIO.IN,
|
||||||
GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
|
GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
|
||||||
|
|
||||||
|
|
||||||
def write_output(port, value):
|
def write_output(port, value):
|
||||||
""" Write a value to a GPIO. """
|
""" Write a value to a GPIO. """
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
GPIO.output(port, value)
|
GPIO.output(port, value)
|
||||||
|
|
||||||
|
|
||||||
def read_input(port):
|
def read_input(port):
|
||||||
""" Read a value from a GPIO. """
|
""" Read a value from a GPIO. """
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
return GPIO.input(port)
|
return GPIO.input(port)
|
||||||
|
|
||||||
|
|
||||||
def edge_detect(port, event_callback, bounce):
|
def edge_detect(port, event_callback, bounce):
|
||||||
""" Adds detection for RISING and FALLING events. """
|
""" Adds detection for RISING and FALLING events. """
|
||||||
|
import RPi.GPIO as GPIO
|
||||||
GPIO.add_event_detect(
|
GPIO.add_event_detect(
|
||||||
port,
|
port,
|
||||||
GPIO.BOTH,
|
GPIO.BOTH,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user