adding pull mode and relay time for you garage door (#2896)

* adding pull mode and relay time

* fixing failing tests

* removed unused vars, removed trailing whitespace

* removed white space

* split line in 2

* removed whitespace and fixed indent

* undid line break

* Update rpi_gpio.py

new line so its not too long

* back to no new line

* Moved long method to a new line

* Moved comment

* moved comment to above method

* adding required blank line

* fixed variables and made them optional

misunderstood the logic at first.

* removed line for lint and removed vars that were not required

* added second blank line for class

* added new configs to platform_schema - still have same error on load

* changing string to int

* added code to covers rpi as well
pull/2955/head
Carter 2016-08-24 01:28:49 -05:00 committed by Paulus Schoutsen
parent 78b2c87b54
commit 52acb2e6f0
2 changed files with 36 additions and 8 deletions

View File

@ -16,6 +16,10 @@ from homeassistant.components.cover import CoverDevice
import homeassistant.components.rpi_gpio as rpi_gpio
import homeassistant.helpers.config_validation as cv
RELAY_TIME = 'relay_time'
STATE_PULL_MODE = 'state_pull_mode'
DEFAULT_PULL_MODE = 'UP'
DEFAULT_RELAY_TIME = .2
DEPENDENCIES = ['rpi_gpio']
_LOGGER = logging.getLogger(__name__)
@ -33,18 +37,24 @@ _COVERS_SCHEMA = vol.All(
PLATFORM_SCHEMA = vol.Schema({
'platform': str,
vol.Required('covers'): _COVERS_SCHEMA,
vol.Optional(STATE_PULL_MODE, default=DEFAULT_PULL_MODE): cv.string,
vol.Optional(RELAY_TIME, default=DEFAULT_RELAY_TIME): vol.Coerce(int),
})
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the cover platform."""
relay_time = config.get(RELAY_TIME)
state_pull_mode = config.get(STATE_PULL_MODE)
covers = []
covers_conf = config.get('covers')
for cover in covers_conf:
covers.append(RPiGPIOCover(cover['name'], cover['relay_pin'],
cover['state_pin']))
cover['state_pin'],
state_pull_mode,
relay_time))
add_devices(covers)
@ -52,14 +62,18 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class RPiGPIOCover(CoverDevice):
"""Representation of a Raspberry cover."""
def __init__(self, name, relay_pin, state_pin):
# pylint: disable=too-many-arguments
def __init__(self, name, relay_pin, state_pin,
state_pull_mode, relay_time):
"""Initialize the cover."""
self._name = name
self._state = False
self._relay_pin = relay_pin
self._state_pin = state_pin
self._state_pull_mode = state_pull_mode
self._relay_time = relay_time
rpi_gpio.setup_output(self._relay_pin)
rpi_gpio.setup_input(self._state_pin, 'UP')
rpi_gpio.setup_input(self._state_pin, self._state_pull_mode)
rpi_gpio.write_output(self._relay_pin, True)
@property
@ -84,7 +98,7 @@ class RPiGPIOCover(CoverDevice):
def _trigger(self):
"""Trigger the cover."""
rpi_gpio.write_output(self._relay_pin, False)
sleep(0.2)
sleep(self._relay_time)
rpi_gpio.write_output(self._relay_pin, True)
def close_cover(self):

View File

@ -15,6 +15,10 @@ from homeassistant.components.garage_door import GarageDoorDevice
import homeassistant.components.rpi_gpio as rpi_gpio
import homeassistant.helpers.config_validation as cv
RELAY_TIME = 'relay_time'
STATE_PULL_MODE = 'state_pull_mode'
DEFAULT_PULL_MODE = 'UP'
DEFAULT_RELAY_TIME = .2
DEPENDENCIES = ['rpi_gpio']
_LOGGER = logging.getLogger(__name__)
@ -32,32 +36,42 @@ _DOORS_SCHEMA = vol.All(
PLATFORM_SCHEMA = vol.Schema({
'platform': str,
vol.Required('doors'): _DOORS_SCHEMA,
vol.Optional(STATE_PULL_MODE, default=DEFAULT_PULL_MODE): cv.string,
vol.Optional(RELAY_TIME, default=DEFAULT_RELAY_TIME): vol.Coerce(int),
})
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the garage door platform."""
relay_time = config.get(RELAY_TIME)
state_pull_mode = config.get(STATE_PULL_MODE)
doors = []
doors_conf = config.get('doors')
for door in doors_conf:
doors.append(RPiGPIOGarageDoor(door['name'], door['relay_pin'],
door['state_pin']))
door['state_pin'],
state_pull_mode,
relay_time))
add_devices(doors)
class RPiGPIOGarageDoor(GarageDoorDevice):
"""Representation of a Raspberry garage door."""
def __init__(self, name, relay_pin, state_pin):
# pylint: disable=too-many-arguments
def __init__(self, name, relay_pin, state_pin,
state_pull_mode, relay_time):
"""Initialize the garage door."""
self._name = name
self._state = False
self._relay_pin = relay_pin
self._state_pin = state_pin
self._state_pull_mode = state_pull_mode
self._relay_time = relay_time
rpi_gpio.setup_output(self._relay_pin)
rpi_gpio.setup_input(self._state_pin, 'UP')
rpi_gpio.setup_input(self._state_pin, self._state_pull_mode)
rpi_gpio.write_output(self._relay_pin, True)
@property
@ -82,7 +96,7 @@ class RPiGPIOGarageDoor(GarageDoorDevice):
def _trigger(self):
"""Trigger the door."""
rpi_gpio.write_output(self._relay_pin, False)
sleep(0.2)
sleep(self._relay_time)
rpi_gpio.write_output(self._relay_pin, True)
def close_door(self):