* Upgrade pylint to 1.8.1 * Fix no-else-return * Fix bad-whitespace * Fix too-many-nested-blocks * Fix raising-format-tuple See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst * Fix len-as-condition * Fix logging-not-lazy Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string * Fix stop-iteration-return * Fix useless-super-delegation * Fix trailing-comma-tuple Both of these seem to simply be bugs: * Nest: The value of self._humidity never seems to be used anywhere * Dovado: The called API method seems to expect a "normal" number * Fix redefined-argument-from-local * Fix consider-using-enumerate * Fix wrong-import-order * Fix arguments-differ * Fix missed no-else-return * Fix no-member and related * Fix signatures-differ * Revert "Upgrade pylint to 1.8.1" This reverts commit af78aa00f125a7d34add97b9d50c14db48412211. * Fix arguments-differ * except for device_tracker * Cleanup * Fix test using positional argument * Fix line too long I forgot to run flake8 - shame on me... 🙃 * Fix bad-option-value for 1.6.5 * Fix arguments-differ for device_tracker * Upgrade pylint to 1.8.2 * 👕 Fix missed no-member
120 lines
3.8 KiB
Python
120 lines
3.8 KiB
Python
"""
|
|
Support for controlling a Raspberry Pi cover.
|
|
|
|
Instructions for building the controller can be found here
|
|
https://github.com/andrewshilliday/garage-door-controller
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/cover.rpi_gpio/
|
|
"""
|
|
import logging
|
|
from time import sleep
|
|
|
|
import voluptuous as vol
|
|
|
|
from homeassistant.components.cover import CoverDevice, PLATFORM_SCHEMA
|
|
from homeassistant.const import CONF_NAME
|
|
import homeassistant.components.rpi_gpio as rpi_gpio
|
|
import homeassistant.helpers.config_validation as cv
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
CONF_COVERS = 'covers'
|
|
CONF_RELAY_PIN = 'relay_pin'
|
|
CONF_RELAY_TIME = 'relay_time'
|
|
CONF_STATE_PIN = 'state_pin'
|
|
CONF_STATE_PULL_MODE = 'state_pull_mode'
|
|
CONF_INVERT_STATE = 'invert_state'
|
|
CONF_INVERT_RELAY = 'invert_relay'
|
|
|
|
DEFAULT_RELAY_TIME = .2
|
|
DEFAULT_STATE_PULL_MODE = 'UP'
|
|
DEFAULT_INVERT_STATE = False
|
|
DEFAULT_INVERT_RELAY = False
|
|
DEPENDENCIES = ['rpi_gpio']
|
|
|
|
_COVERS_SCHEMA = vol.All(
|
|
cv.ensure_list,
|
|
[
|
|
vol.Schema({
|
|
CONF_NAME: cv.string,
|
|
CONF_RELAY_PIN: cv.positive_int,
|
|
CONF_STATE_PIN: cv.positive_int,
|
|
})
|
|
]
|
|
)
|
|
|
|
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|
vol.Required(CONF_COVERS): _COVERS_SCHEMA,
|
|
vol.Optional(CONF_STATE_PULL_MODE, default=DEFAULT_STATE_PULL_MODE):
|
|
cv.string,
|
|
vol.Optional(CONF_RELAY_TIME, default=DEFAULT_RELAY_TIME): cv.positive_int,
|
|
vol.Optional(CONF_INVERT_STATE, default=DEFAULT_INVERT_STATE): cv.boolean,
|
|
vol.Optional(CONF_INVERT_RELAY, default=DEFAULT_INVERT_RELAY): cv.boolean,
|
|
})
|
|
|
|
|
|
# pylint: disable=unused-argument
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
"""Set up the RPi cover platform."""
|
|
relay_time = config.get(CONF_RELAY_TIME)
|
|
state_pull_mode = config.get(CONF_STATE_PULL_MODE)
|
|
invert_state = config.get(CONF_INVERT_STATE)
|
|
invert_relay = config.get(CONF_INVERT_RELAY)
|
|
covers = []
|
|
covers_conf = config.get(CONF_COVERS)
|
|
|
|
for cover in covers_conf:
|
|
covers.append(RPiGPIOCover(
|
|
cover[CONF_NAME], cover[CONF_RELAY_PIN], cover[CONF_STATE_PIN],
|
|
state_pull_mode, relay_time, invert_state, invert_relay))
|
|
add_devices(covers)
|
|
|
|
|
|
class RPiGPIOCover(CoverDevice):
|
|
"""Representation of a Raspberry GPIO cover."""
|
|
|
|
def __init__(self, name, relay_pin, state_pin, state_pull_mode,
|
|
relay_time, invert_state, invert_relay):
|
|
"""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
|
|
self._invert_state = invert_state
|
|
self._invert_relay = invert_relay
|
|
rpi_gpio.setup_output(self._relay_pin)
|
|
rpi_gpio.setup_input(self._state_pin, self._state_pull_mode)
|
|
rpi_gpio.write_output(self._relay_pin, not self._invert_relay)
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the cover if any."""
|
|
return self._name
|
|
|
|
def update(self):
|
|
"""Update the state of the cover."""
|
|
self._state = rpi_gpio.read_input(self._state_pin)
|
|
|
|
@property
|
|
def is_closed(self):
|
|
"""Return true if cover is closed."""
|
|
return self._state != self._invert_state
|
|
|
|
def _trigger(self):
|
|
"""Trigger the cover."""
|
|
rpi_gpio.write_output(self._relay_pin, self._invert_relay)
|
|
sleep(self._relay_time)
|
|
rpi_gpio.write_output(self._relay_pin, not self._invert_relay)
|
|
|
|
def close_cover(self, **kwargs):
|
|
"""Close the cover."""
|
|
if not self.is_closed:
|
|
self._trigger()
|
|
|
|
def open_cover(self, **kwargs):
|
|
"""Open the cover."""
|
|
if self.is_closed:
|
|
self._trigger()
|