mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
fix a couple of typos and use port(s) everywhere
This commit is contained in:
parent
1f3bde3e08
commit
87bf3c4e0d
@ -1,9 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
homeassistant.components.switch.rpi_gpio
|
homeassistant.components.switch.rpi_gpio
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
Allows to control the GPIO pins of a Raspberry Pi.
|
||||||
Allows to control a swith using Raspberry GPIO.
|
|
||||||
Support for switching Raspberry GPIO pins on and off.
|
|
||||||
|
|
||||||
Configuration:
|
Configuration:
|
||||||
|
|
||||||
@ -17,8 +15,7 @@ Variables:
|
|||||||
|
|
||||||
ports
|
ports
|
||||||
*Required
|
*Required
|
||||||
An array specifying the GPIO ports to use and the name usd in the fronted.
|
An array specifying the GPIO ports to use and the name to use in the frontend.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
try:
|
try:
|
||||||
@ -36,9 +33,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
""" Sets up the Raspberry PI GPIO switches. """
|
""" Sets up the Raspberry PI GPIO ports. """
|
||||||
if GPIO is None:
|
if GPIO is None:
|
||||||
_LOGGER.error('RPi.GPIO not available. rpi_gpio switches ignored.')
|
_LOGGER.error('RPi.GPIO not available. rpi_gpio ports ignored.')
|
||||||
return
|
return
|
||||||
|
|
||||||
switches = []
|
switches = []
|
||||||
@ -48,22 +45,19 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||||||
add_devices(switches)
|
add_devices(switches)
|
||||||
|
|
||||||
def cleanup_gpio(event):
|
def cleanup_gpio(event):
|
||||||
""" Stuff to do before stop home assistant """
|
""" Stuff to do before stop home assistant. """
|
||||||
# pylint: disable=no-member
|
# pylint: disable=no-member
|
||||||
GPIO.cleanup()
|
GPIO.cleanup()
|
||||||
|
|
||||||
def prepare_gpio(event):
|
def prepare_gpio(event):
|
||||||
""" Stuff to do when home assistant starts"""
|
""" Stuff to do when home assistant starts. """
|
||||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gpio)
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gpio)
|
||||||
|
|
||||||
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_gpio)
|
hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_gpio)
|
||||||
|
|
||||||
|
|
||||||
class RPiGPIOSwitch(ToggleEntity):
|
class RPiGPIOSwitch(ToggleEntity):
|
||||||
|
""" Represents a port that can be toggled using Raspberry Pi GPIO. """
|
||||||
'''
|
|
||||||
Represents a switch that can be toggled using Raspberry Pi GPIO.
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, name, gpio):
|
def __init__(self, name, gpio):
|
||||||
self._name = name or DEVICE_DEFAULT_NAME
|
self._name = name or DEVICE_DEFAULT_NAME
|
||||||
@ -74,12 +68,12 @@ class RPiGPIOSwitch(ToggleEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" The name of the port """
|
""" The name of the port. """
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
""" No polling needed """
|
""" No polling needed. """
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -100,7 +94,7 @@ class RPiGPIOSwitch(ToggleEntity):
|
|||||||
self.update_ha_state()
|
self.update_ha_state()
|
||||||
|
|
||||||
def _switch(self, new_state):
|
def _switch(self, new_state):
|
||||||
""" Change the output value to Raspberry Pi GPIO port """
|
""" Change the output value to Raspberry Pi GPIO port. """
|
||||||
_LOGGER.info('Setting GPIO %s to %s', self._gpio, new_state)
|
_LOGGER.info('Setting GPIO %s to %s', self._gpio, new_state)
|
||||||
# pylint: disable=bare-except
|
# pylint: disable=bare-except
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user