From 8617b92d1b064dc193a68ba9668d8cccdefaba66 Mon Sep 17 00:00:00 2001 From: sfam Date: Fri, 15 Jan 2016 11:59:58 +0000 Subject: [PATCH 1/6] Update RPi.GPIO version and code refactoring --- .coveragerc | 1 + .../components/binary_sensor/rpi_gpio.py | 73 ++++++++++++++++ homeassistant/components/rpi_gpio.py | 68 +++++++++++++++ homeassistant/components/sensor/rpi_gpio.py | 81 +++++------------- homeassistant/components/switch/rpi_gpio.py | 84 ++++--------------- requirements_all.txt | 3 +- 6 files changed, 182 insertions(+), 128 deletions(-) create mode 100644 homeassistant/components/binary_sensor/rpi_gpio.py create mode 100644 homeassistant/components/rpi_gpio.py diff --git a/.coveragerc b/.coveragerc index f5eabf3b7f6..8f83575342c 100644 --- a/.coveragerc +++ b/.coveragerc @@ -43,6 +43,7 @@ omit = homeassistant/components/binary_sensor/arest.py homeassistant/components/binary_sensor/rest.py + homeassistant/components/binary_sensor/rpi_gpio.py homeassistant/components/browser.py homeassistant/components/camera/* homeassistant/components/device_tracker/actiontec.py diff --git a/homeassistant/components/binary_sensor/rpi_gpio.py b/homeassistant/components/binary_sensor/rpi_gpio.py new file mode 100644 index 00000000000..b6fb43a8372 --- /dev/null +++ b/homeassistant/components/binary_sensor/rpi_gpio.py @@ -0,0 +1,73 @@ +""" +homeassistant.components.binary_sensor.rpi_gpio +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Allows to configure a binary_sensor state sensor using RPi GPIO. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/binary_sensor.rpi_gpio/ +""" + +import logging +import homeassistant.components.rpi_gpio as rpi_gpio +from homeassistant.helpers.entity import Entity +from homeassistant.const import (STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME) + +DEFAULT_PULL_MODE = "UP" +DEFAULT_BOUNCETIME = 50 +DEFAULT_INVERT_LOGIC = False + +DEPENDENCIES = ['rpi_gpio'] +_LOGGER = logging.getLogger(__name__) + + +# pylint: disable=unused-argument +def setup_platform(hass, config, add_devices, discovery_info=None): + """ Sets up the Raspberry PI GPIO ports. """ + + pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE) + bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME) + invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC) + + binary_sensors = [] + ports = config.get('ports') + for port_num, port_name in ports.items(): + binary_sensors.append(RPiGPIOBinarySensor( + port_name, port_num, pull_mode, bouncetime, invert_logic)) + add_devices(binary_sensors) + + +# pylint: disable=too-many-arguments, too-many-instance-attributes +class RPiGPIOBinarySensor(Entity): + """ Sets up the Raspberry PI GPIO ports. """ + def __init__(self, name, port, pull_mode, bouncetime, invert_logic): + # pylint: disable=no-member + + self._name = name or DEVICE_DEFAULT_NAME + self._port = port + self._pull_mode = pull_mode + self._bouncetime = bouncetime + self._invert_logic = invert_logic + + rpi_gpio.setup_input(self._port, self._pull_mode) + self._state = rpi_gpio.read_input(self._port) + + def read_gpio(port): + """ Reads state from GPIO. """ + self._state = rpi_gpio.read_input(self._port) + self.update_ha_state() + rpi_gpio.edge_detect(self._port, read_gpio, self._bouncetime) + + @property + def should_poll(self): + """ No polling needed. """ + return False + + @property + def name(self): + """ The name of the sensor. """ + return self._name + + @property + def state(self): + """ Returns the state of the entity. """ + return STATE_ON if self._state != self._invert_logic else STATE_OFF diff --git a/homeassistant/components/rpi_gpio.py b/homeassistant/components/rpi_gpio.py new file mode 100644 index 00000000000..cb81fecfdc0 --- /dev/null +++ b/homeassistant/components/rpi_gpio.py @@ -0,0 +1,68 @@ +""" +homeassistant.components.switch.rpi_gpio +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Allows to control the GPIO pins of a Raspberry Pi. + +For more details about this platform, please refer to the documentation at +https://home-assistant.io/components/switch.rpi_gpio/ +""" +import logging +try: + import RPi.GPIO as GPIO +except ImportError: + GPIO = None +from homeassistant.const import (EVENT_HOMEASSISTANT_START, + EVENT_HOMEASSISTANT_STOP) +REQUIREMENTS = ['RPi.GPIO==0.6.1'] +DOMAIN = "rpi_gpio" +_LOGGER = logging.getLogger(__name__) + + +# pylint: disable=no-member +def setup(hass, config): + """ Sets up the Raspberry PI GPIO ports. """ + if GPIO is None: + _LOGGER.error('RPi.GPIO not available. rpi_gpio ports ignored.') + return False + + def cleanup_gpio(event): + """ Stuff to do before stop home assistant. """ + GPIO.cleanup() + + def prepare_gpio(event): + """ Stuff to do when home assistant starts. """ + hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gpio) + + hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_gpio) + GPIO.setmode(GPIO.BCM) + return True + + +def setup_output(port): + """ Setup a GPIO as output """ + GPIO.setup(port, GPIO.OUT) + + +def setup_input(port, pull_mode): + """ Setup a GPIO as input """ + GPIO.setup(port, GPIO.IN, + GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP) + + +def write_output(port, value): + """ Write a value to a GPIO""" + GPIO.output(port, value) + + +def read_input(port): + """ Read a value from a GPIO""" + return GPIO.input(port) + + +def edge_detect(port, event_callback, bounce): + """ Adds detection for RISING and FALLING events """ + GPIO.add_event_detect( + port, + GPIO.BOTH, + callback=event_callback, + bouncetime=bounce) diff --git a/homeassistant/components/sensor/rpi_gpio.py b/homeassistant/components/sensor/rpi_gpio.py index ef7ea8c33c1..415e717a6b0 100644 --- a/homeassistant/components/sensor/rpi_gpio.py +++ b/homeassistant/components/sensor/rpi_gpio.py @@ -6,92 +6,51 @@ Allows to configure a binary state sensor using RPi GPIO. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.rpi_gpio/ """ -# pylint: disable=import-error -import logging -from homeassistant.helpers.entity import Entity -from homeassistant.const import (DEVICE_DEFAULT_NAME, - EVENT_HOMEASSISTANT_START, - EVENT_HOMEASSISTANT_STOP) +import logging +from homeassistant.components.binary_sensor.rpi_gpio import RPiGPIOBinarySensor DEFAULT_PULL_MODE = "UP" +DEFAULT_BOUNCETIME = 50 DEFAULT_VALUE_HIGH = "HIGH" DEFAULT_VALUE_LOW = "LOW" -DEFAULT_BOUNCETIME = 50 -REQUIREMENTS = ['RPi.GPIO==0.5.11'] +DEPENDENCIES = ['rpi_gpio'] _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the Raspberry PI GPIO ports. """ - import RPi.GPIO as GPIO - GPIO.setmode(GPIO.BCM) - sensors = [] pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE) + bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME) value_high = config.get('value_high', DEFAULT_VALUE_HIGH) value_low = config.get('value_low', DEFAULT_VALUE_LOW) - bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME) + + sensors = [] ports = config.get('ports') - for port_num, port_name in ports.items(): + for port, name in ports.items(): sensors.append(RPiGPIOSensor( - port_name, port_num, pull_mode, - value_high, value_low, bouncetime)) + name, port, pull_mode, bouncetime, + value_high, value_low)) add_devices(sensors) - def cleanup_gpio(event): - """ Stuff to do before stop home assistant. """ - # pylint: disable=no-member - GPIO.cleanup() - - def prepare_gpio(event): - """ Stuff to do when home assistant starts. """ - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gpio) - - hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_gpio) - # pylint: disable=too-many-arguments, too-many-instance-attributes -class RPiGPIOSensor(Entity): +class RPiGPIOSensor(RPiGPIOBinarySensor): """ Sets up the Raspberry PI GPIO ports. """ - def __init__(self, port_name, port_num, pull_mode, - value_high, value_low, bouncetime): - # pylint: disable=no-member - import RPi.GPIO as GPIO - self._name = port_name or DEVICE_DEFAULT_NAME - self._port = port_num - self._pull = GPIO.PUD_DOWN if pull_mode == "DOWN" else GPIO.PUD_UP - self._vhigh = value_high - self._vlow = value_low - self._bouncetime = bouncetime - GPIO.setup(self._port, GPIO.IN, pull_up_down=self._pull) - self._state = self._vhigh if GPIO.input(self._port) else self._vlow + def __init__(self, name, port, pull_mode, bouncetime, + value_high, value_low): - def edge_callback(channel): - """ port changed state """ - # pylint: disable=no-member - self._state = self._vhigh if GPIO.input(channel) else self._vlow - self.update_ha_state() - - GPIO.add_event_detect( - self._port, - GPIO.BOTH, - callback=edge_callback, - bouncetime=self._bouncetime) - - @property - def should_poll(self): - """ No polling needed. """ - return False - - @property - def name(self): - """ The name of the sensor. """ - return self._name + self._value_high = value_high + self._value_low = value_low + super().__init__(name, port, pull_mode, bouncetime, False) @property def state(self): """ Returns the state of the entity. """ - return self._state + if self._state != self._invert_logic: + return self._value_high + else: + return self._value_low diff --git a/homeassistant/components/switch/rpi_gpio.py b/homeassistant/components/switch/rpi_gpio.py index 1c36aa262f4..3a3256e5591 100644 --- a/homeassistant/components/switch/rpi_gpio.py +++ b/homeassistant/components/switch/rpi_gpio.py @@ -7,59 +7,38 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/switch.rpi_gpio/ """ import logging -try: - import RPi.GPIO as GPIO -except ImportError: - GPIO = None +import homeassistant.components.rpi_gpio as rpi_gpio from homeassistant.helpers.entity import ToggleEntity -from homeassistant.const import (DEVICE_DEFAULT_NAME, - EVENT_HOMEASSISTANT_START, - EVENT_HOMEASSISTANT_STOP) +from homeassistant.const import (DEVICE_DEFAULT_NAME) DEFAULT_INVERT_LOGIC = False -REQUIREMENTS = ['RPi.GPIO==0.5.11'] +DEPENDENCIES = ['rpi_gpio'] _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): """ Sets up the Raspberry PI GPIO ports. """ - if GPIO is None: - _LOGGER.error('RPi.GPIO not available. rpi_gpio ports ignored.') - return - # pylint: disable=no-member - GPIO.setmode(GPIO.BCM) + + invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC) switches = [] - invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC) ports = config.get('ports') - for port_num, port_name in ports.items(): - switches.append(RPiGPIOSwitch(port_name, port_num, invert_logic)) + for port, name in ports.items(): + switches.append(RPiGPIOSwitch(name, port, invert_logic)) add_devices(switches) - def cleanup_gpio(event): - """ Stuff to do before stop home assistant. """ - # pylint: disable=no-member - GPIO.cleanup() - - def prepare_gpio(event): - """ Stuff to do when home assistant starts. """ - hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, cleanup_gpio) - - hass.bus.listen_once(EVENT_HOMEASSISTANT_START, prepare_gpio) - class RPiGPIOSwitch(ToggleEntity): """ Represents a port that can be toggled using Raspberry Pi GPIO. """ - def __init__(self, name, gpio, invert_logic): + def __init__(self, name, port, invert_logic): self._name = name or DEVICE_DEFAULT_NAME - self._gpio = gpio - self._active_state = not invert_logic - self._state = not self._active_state - # pylint: disable=no-member - GPIO.setup(gpio, GPIO.OUT) + self._port = port + self._invert_logic = invert_logic + self._state = False + rpi_gpio.setup_output(self._port) @property def name(self): @@ -76,41 +55,14 @@ class RPiGPIOSwitch(ToggleEntity): """ True if device is on. """ return self._state - def turn_on(self, **kwargs): + def turn_on(self): """ Turn the device on. """ - if self._switch(self._active_state): - self._state = True + rpi_gpio.write_output(self._port, 0 if self._invert_logic else 1) + self._state = True self.update_ha_state() - def turn_off(self, **kwargs): + def turn_off(self): """ Turn the device off. """ - if self._switch(not self._active_state): - self._state = False + rpi_gpio.write_output(self._port, 1 if self._invert_logic else 0) + self._state = False self.update_ha_state() - - def _switch(self, new_state): - """ Change the output value to Raspberry Pi GPIO port. """ - _LOGGER.info('Setting GPIO %s to %s', self._gpio, new_state) - # pylint: disable=bare-except - try: - # pylint: disable=no-member - GPIO.output(self._gpio, 1 if new_state else 0) - except: - _LOGGER.error('GPIO "%s" output failed', self._gpio) - return False - return True - - # pylint: disable=no-self-use - @property - def device_state_attributes(self): - """ Returns device specific state attributes. """ - return None - - @property - def state_attributes(self): - """ Returns optional state attributes. """ - data = {} - device_attr = self.device_state_attributes - if device_attr is not None: - data.update(device_attr) - return data diff --git a/requirements_all.txt b/requirements_all.txt index 4d38ada0daf..a11e42e5b60 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -146,9 +146,10 @@ https://github.com/HydrelioxGitHub/netatmo-api-python/archive/43ff238a0122b0939a # homeassistant.components.sensor.openweathermap pyowm==2.3.0 +# homeassistant.components.binary_sensor.rpi_gpio # homeassistant.components.sensor.rpi_gpio # homeassistant.components.switch.rpi_gpio -# RPi.GPIO==0.5.11 +# RPi.GPIO==0.6.1 # homeassistant.components.sensor.sabnzbd https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1 From 7c925ac295830459954d3aa1663b6a0525734949 Mon Sep 17 00:00:00 2001 From: sfam Date: Fri, 15 Jan 2016 12:35:06 +0000 Subject: [PATCH 2/6] update comments --- .../components/binary_sensor/rpi_gpio.py | 6 +++--- homeassistant/components/rpi_gpio.py | 15 ++++++++------- homeassistant/components/sensor/rpi_gpio.py | 6 +++--- homeassistant/components/switch/rpi_gpio.py | 10 +++++----- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/binary_sensor/rpi_gpio.py b/homeassistant/components/binary_sensor/rpi_gpio.py index b6fb43a8372..972c319d958 100644 --- a/homeassistant/components/binary_sensor/rpi_gpio.py +++ b/homeassistant/components/binary_sensor/rpi_gpio.py @@ -1,7 +1,7 @@ """ homeassistant.components.binary_sensor.rpi_gpio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Allows to configure a binary_sensor state sensor using RPi GPIO. +Allows to configure a binary_sensor using RPi GPIO. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/binary_sensor.rpi_gpio/ @@ -22,7 +22,7 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): - """ Sets up the Raspberry PI GPIO ports. """ + """ Sets up the Raspberry PI GPIO devices. """ pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE) bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME) @@ -38,7 +38,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # pylint: disable=too-many-arguments, too-many-instance-attributes class RPiGPIOBinarySensor(Entity): - """ Sets up the Raspberry PI GPIO ports. """ + """ Represents a binary sensor that uses Raspberry Pi GPIO. """ def __init__(self, name, port, pull_mode, bouncetime, invert_logic): # pylint: disable=no-member diff --git a/homeassistant/components/rpi_gpio.py b/homeassistant/components/rpi_gpio.py index cb81fecfdc0..86800a36dbe 100644 --- a/homeassistant/components/rpi_gpio.py +++ b/homeassistant/components/rpi_gpio.py @@ -4,8 +4,9 @@ homeassistant.components.switch.rpi_gpio Allows to control the GPIO pins of a Raspberry Pi. For more details about this platform, please refer to the documentation at -https://home-assistant.io/components/switch.rpi_gpio/ +https://home-assistant.io/components/rpi_gpio/ """ + import logging try: import RPi.GPIO as GPIO @@ -20,7 +21,7 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=no-member def setup(hass, config): - """ Sets up the Raspberry PI GPIO ports. """ + """ Sets up the Raspberry PI GPIO component. """ if GPIO is None: _LOGGER.error('RPi.GPIO not available. rpi_gpio ports ignored.') return False @@ -39,28 +40,28 @@ def setup(hass, config): def setup_output(port): - """ Setup a GPIO as output """ + """ Setup a GPIO as output. """ GPIO.setup(port, GPIO.OUT) def setup_input(port, pull_mode): - """ Setup a GPIO as input """ + """ Setup a GPIO as input. """ GPIO.setup(port, GPIO.IN, GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP) def write_output(port, value): - """ Write a value to a GPIO""" + """ Write a value to a GPIO. """ GPIO.output(port, value) def read_input(port): - """ Read a value from a GPIO""" + """ Read a value from a GPIO. """ return GPIO.input(port) def edge_detect(port, event_callback, bounce): - """ Adds detection for RISING and FALLING events """ + """ Adds detection for RISING and FALLING events. """ GPIO.add_event_detect( port, GPIO.BOTH, diff --git a/homeassistant/components/sensor/rpi_gpio.py b/homeassistant/components/sensor/rpi_gpio.py index 415e717a6b0..d07375f9e31 100644 --- a/homeassistant/components/sensor/rpi_gpio.py +++ b/homeassistant/components/sensor/rpi_gpio.py @@ -1,7 +1,7 @@ """ homeassistant.components.sensor.rpi_gpio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Allows to configure a binary state sensor using RPi GPIO. +Allows to configure a sensor using RPi GPIO. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/sensor.rpi_gpio/ @@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): - """ Sets up the Raspberry PI GPIO ports. """ + """ Sets up the Raspberry PI GPIO devices. """ pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE) bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME) @@ -39,7 +39,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # pylint: disable=too-many-arguments, too-many-instance-attributes class RPiGPIOSensor(RPiGPIOBinarySensor): - """ Sets up the Raspberry PI GPIO ports. """ + """ Represents a sensor that uses Raspberry Pi GPIO. """ def __init__(self, name, port, pull_mode, bouncetime, value_high, value_low): diff --git a/homeassistant/components/switch/rpi_gpio.py b/homeassistant/components/switch/rpi_gpio.py index 3a3256e5591..dffa4682279 100644 --- a/homeassistant/components/switch/rpi_gpio.py +++ b/homeassistant/components/switch/rpi_gpio.py @@ -1,11 +1,12 @@ """ homeassistant.components.switch.rpi_gpio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Allows to control the GPIO pins of a Raspberry Pi. +Allows to configure a switch using RPi GPIO. For more details about this platform, please refer to the documentation at https://home-assistant.io/components/switch.rpi_gpio/ """ + import logging import homeassistant.components.rpi_gpio as rpi_gpio from homeassistant.helpers.entity import ToggleEntity @@ -19,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) # pylint: disable=unused-argument def setup_platform(hass, config, add_devices, discovery_info=None): - """ Sets up the Raspberry PI GPIO ports. """ + """ Sets up the Raspberry PI GPIO devices. """ invert_logic = config.get('invert_logic', DEFAULT_INVERT_LOGIC) @@ -31,8 +32,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): 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, port, invert_logic): self._name = name or DEVICE_DEFAULT_NAME self._port = port @@ -42,7 +42,7 @@ class RPiGPIOSwitch(ToggleEntity): @property def name(self): - """ The name of the port. """ + """ The name of the switch. """ return self._name @property From 127488004c3698e2ec280bac7f4c87d55f331c99 Mon Sep 17 00:00:00 2001 From: sfam Date: Fri, 15 Jan 2016 17:16:02 +0000 Subject: [PATCH 3/6] update coveragerc and requirements_all --- .coveragerc | 6 +++--- requirements_all.txt | 23 +++++------------------ 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/.coveragerc b/.coveragerc index 8f83575342c..adb3c59765e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -41,9 +41,11 @@ omit = homeassistant/components/mysensors.py homeassistant/components/*/mysensors.py + homeassistant/components/rpi_gpio.py + homeassistant/components/*/rpi_gpio.py + homeassistant/components/binary_sensor/arest.py homeassistant/components/binary_sensor/rest.py - homeassistant/components/binary_sensor/rpi_gpio.py homeassistant/components/browser.py homeassistant/components/camera/* homeassistant/components/device_tracker/actiontec.py @@ -102,7 +104,6 @@ omit = homeassistant/components/sensor/netatmo.py homeassistant/components/sensor/openweathermap.py homeassistant/components/sensor/rest.py - homeassistant/components/sensor/rpi_gpio.py homeassistant/components/sensor/sabnzbd.py homeassistant/components/sensor/swiss_public_transport.py homeassistant/components/sensor/systemmonitor.py @@ -118,7 +119,6 @@ omit = homeassistant/components/switch/mystrom.py homeassistant/components/switch/orvibo.py homeassistant/components/switch/rest.py - homeassistant/components/switch/rpi_gpio.py homeassistant/components/switch/transmission.py homeassistant/components/switch/wemo.py homeassistant/components/thermostat/heatmiser.py diff --git a/requirements_all.txt b/requirements_all.txt index a11e42e5b60..f320408f138 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -6,9 +6,6 @@ pip>=7.0.0 vincenty==0.1.3 jinja2>=2.8 -# homeassistant.components.alarm_control_panel.alarmdotcom -https://github.com/Xorso/pyalarmdotcom/archive/0.0.7.zip#pyalarmdotcom==0.0.7 - # homeassistant.components.arduino PyMata==2.07a @@ -62,14 +59,14 @@ tellcore-py==1.1.2 # homeassistant.components.light.vera # homeassistant.components.sensor.vera # homeassistant.components.switch.vera -pyvera==0.2.5 +pyvera==0.2.3 # homeassistant.components.wink # homeassistant.components.light.wink # homeassistant.components.lock.wink # homeassistant.components.sensor.wink # homeassistant.components.switch.wink -python-wink==0.4.1 +python-wink==0.3.1 # homeassistant.components.media_player.cast pychromecast==0.6.14 @@ -92,12 +89,6 @@ https://github.com/bashwork/pymodbus/archive/d7fc4f1cc975631e0a9011390e8017f64b6 # homeassistant.components.mqtt paho-mqtt==1.1 -# homeassistant.components.mysensors -https://github.com/theolind/pymysensors/archive/005bff4c5ca7a56acd30e816bc3bcdb5cb2d46fd.zip#pymysensors==0.4 - -# homeassistant.components.notify.free_mobile -freesms==0.1.0 - # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0 @@ -140,16 +131,15 @@ eliqonline==1.0.11 # homeassistant.components.sensor.forecast python-forecastio==1.3.3 -# homeassistant.components.sensor.netatmo -https://github.com/HydrelioxGitHub/netatmo-api-python/archive/43ff238a0122b0939a0dc4e8836b6782913fb6e2.zip#lnetatmo==0.4.0 +# homeassistant.components.sensor.mysensors +https://github.com/theolind/pymysensors/archive/d4b809c2167650691058d1e29bfd2c4b1792b4b0.zip#pymysensors==0.3 # homeassistant.components.sensor.openweathermap pyowm==2.3.0 -# homeassistant.components.binary_sensor.rpi_gpio # homeassistant.components.sensor.rpi_gpio # homeassistant.components.switch.rpi_gpio -# RPi.GPIO==0.6.1 +# RPi.GPIO==0.5.11 # homeassistant.components.sensor.sabnzbd https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1 @@ -197,9 +187,6 @@ evohomeclient==0.2.4 # homeassistant.components.thermostat.nest python-nest==2.6.0 -# homeassistant.components.thermostat.proliphix -proliphix==0.1.0 - # homeassistant.components.thermostat.radiotherm radiotherm==1.2 From 702dddbb2fa476cec7d8d6d42a90562ae23dc943 Mon Sep 17 00:00:00 2001 From: sfam Date: Fri, 15 Jan 2016 17:28:32 +0000 Subject: [PATCH 4/6] update requirements_all --- requirements_all.txt | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/requirements_all.txt b/requirements_all.txt index f320408f138..268ead4d814 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -6,6 +6,9 @@ pip>=7.0.0 vincenty==0.1.3 jinja2>=2.8 +# homeassistant.components.alarm_control_panel.alarmdotcom +https://github.com/Xorso/pyalarmdotcom/archive/0.0.7.zip#pyalarmdotcom==0.0.7 + # homeassistant.components.arduino PyMata==2.07a @@ -59,14 +62,14 @@ tellcore-py==1.1.2 # homeassistant.components.light.vera # homeassistant.components.sensor.vera # homeassistant.components.switch.vera -pyvera==0.2.3 +pyvera==0.2.5 # homeassistant.components.wink # homeassistant.components.light.wink # homeassistant.components.lock.wink # homeassistant.components.sensor.wink # homeassistant.components.switch.wink -python-wink==0.3.1 +python-wink==0.4.1 # homeassistant.components.media_player.cast pychromecast==0.6.14 @@ -89,6 +92,12 @@ https://github.com/bashwork/pymodbus/archive/d7fc4f1cc975631e0a9011390e8017f64b6 # homeassistant.components.mqtt paho-mqtt==1.1 +# homeassistant.components.mysensors +https://github.com/theolind/pymysensors/archive/005bff4c5ca7a56acd30e816bc3bcdb5cb2d46fd.zip#pymysensors==0.4 + +# homeassistant.components.notify.free_mobile +freesms==0.1.0 + # homeassistant.components.notify.pushbullet pushbullet.py==0.9.0 @@ -113,6 +122,9 @@ dnspython3==1.12.0 # homeassistant.components.rfxtrx https://github.com/Danielhiversen/pyRFXtrx/archive/0.2.zip#RFXtrx==0.2 +# homeassistant.components.rpi_gpio +# RPi.GPIO==0.6.1 + # homeassistant.components.sensor.bitcoin blockchain==1.1.2 @@ -131,16 +143,12 @@ eliqonline==1.0.11 # homeassistant.components.sensor.forecast python-forecastio==1.3.3 -# homeassistant.components.sensor.mysensors -https://github.com/theolind/pymysensors/archive/d4b809c2167650691058d1e29bfd2c4b1792b4b0.zip#pymysensors==0.3 +# homeassistant.components.sensor.netatmo +https://github.com/HydrelioxGitHub/netatmo-api-python/archive/43ff238a0122b0939a0dc4e8836b6782913fb6e2.zip#lnetatmo==0.4.0 # homeassistant.components.sensor.openweathermap pyowm==2.3.0 -# homeassistant.components.sensor.rpi_gpio -# homeassistant.components.switch.rpi_gpio -# RPi.GPIO==0.5.11 - # homeassistant.components.sensor.sabnzbd https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1 @@ -187,6 +195,9 @@ evohomeclient==0.2.4 # homeassistant.components.thermostat.nest python-nest==2.6.0 +# homeassistant.components.thermostat.proliphix +proliphix==0.1.0 + # homeassistant.components.thermostat.radiotherm radiotherm==1.2 From d8d59d9a663bdd5b010de363d2b9823284ba82bb Mon Sep 17 00:00:00 2001 From: sfam Date: Fri, 15 Jan 2016 18:05:48 +0000 Subject: [PATCH 5/6] remove rpi_gpio sensor --- .../components/binary_sensor/rpi_gpio.py | 8 +-- homeassistant/components/rpi_gpio.py | 2 +- homeassistant/components/sensor/rpi_gpio.py | 56 ------------------- 3 files changed, 5 insertions(+), 61 deletions(-) delete mode 100644 homeassistant/components/sensor/rpi_gpio.py diff --git a/homeassistant/components/binary_sensor/rpi_gpio.py b/homeassistant/components/binary_sensor/rpi_gpio.py index 972c319d958..39a7edecb79 100644 --- a/homeassistant/components/binary_sensor/rpi_gpio.py +++ b/homeassistant/components/binary_sensor/rpi_gpio.py @@ -10,7 +10,7 @@ https://home-assistant.io/components/binary_sensor.rpi_gpio/ import logging import homeassistant.components.rpi_gpio as rpi_gpio from homeassistant.helpers.entity import Entity -from homeassistant.const import (STATE_ON, STATE_OFF, DEVICE_DEFAULT_NAME) +from homeassistant.const import (DEVICE_DEFAULT_NAME) DEFAULT_PULL_MODE = "UP" DEFAULT_BOUNCETIME = 50 @@ -37,7 +37,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # pylint: disable=too-many-arguments, too-many-instance-attributes -class RPiGPIOBinarySensor(Entity): +class RPiGPIOBinarySensor(BinarySensorDevice): """ Represents a binary sensor that uses Raspberry Pi GPIO. """ def __init__(self, name, port, pull_mode, bouncetime, invert_logic): # pylint: disable=no-member @@ -68,6 +68,6 @@ class RPiGPIOBinarySensor(Entity): return self._name @property - def state(self): + def is_on(self): """ Returns the state of the entity. """ - return STATE_ON if self._state != self._invert_logic else STATE_OFF + return self._state != self._invert_logic diff --git a/homeassistant/components/rpi_gpio.py b/homeassistant/components/rpi_gpio.py index 86800a36dbe..3d0a068f8ca 100644 --- a/homeassistant/components/rpi_gpio.py +++ b/homeassistant/components/rpi_gpio.py @@ -1,5 +1,5 @@ """ -homeassistant.components.switch.rpi_gpio +homeassistant.components.rpi_gpio ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Allows to control the GPIO pins of a Raspberry Pi. diff --git a/homeassistant/components/sensor/rpi_gpio.py b/homeassistant/components/sensor/rpi_gpio.py deleted file mode 100644 index d07375f9e31..00000000000 --- a/homeassistant/components/sensor/rpi_gpio.py +++ /dev/null @@ -1,56 +0,0 @@ -""" -homeassistant.components.sensor.rpi_gpio -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Allows to configure a sensor using RPi GPIO. - -For more details about this platform, please refer to the documentation at -https://home-assistant.io/components/sensor.rpi_gpio/ -""" - -import logging -from homeassistant.components.binary_sensor.rpi_gpio import RPiGPIOBinarySensor - -DEFAULT_PULL_MODE = "UP" -DEFAULT_BOUNCETIME = 50 -DEFAULT_VALUE_HIGH = "HIGH" -DEFAULT_VALUE_LOW = "LOW" - -DEPENDENCIES = ['rpi_gpio'] -_LOGGER = logging.getLogger(__name__) - - -# pylint: disable=unused-argument -def setup_platform(hass, config, add_devices, discovery_info=None): - """ Sets up the Raspberry PI GPIO devices. """ - - pull_mode = config.get('pull_mode', DEFAULT_PULL_MODE) - bouncetime = config.get('bouncetime', DEFAULT_BOUNCETIME) - value_high = config.get('value_high', DEFAULT_VALUE_HIGH) - value_low = config.get('value_low', DEFAULT_VALUE_LOW) - - sensors = [] - ports = config.get('ports') - for port, name in ports.items(): - sensors.append(RPiGPIOSensor( - name, port, pull_mode, bouncetime, - value_high, value_low)) - add_devices(sensors) - - -# pylint: disable=too-many-arguments, too-many-instance-attributes -class RPiGPIOSensor(RPiGPIOBinarySensor): - """ Represents a sensor that uses Raspberry Pi GPIO. """ - def __init__(self, name, port, pull_mode, bouncetime, - value_high, value_low): - - self._value_high = value_high - self._value_low = value_low - super().__init__(name, port, pull_mode, bouncetime, False) - - @property - def state(self): - """ Returns the state of the entity. """ - if self._state != self._invert_logic: - return self._value_high - else: - return self._value_low From 48b6c5b5cb237d27ca1f1a192ab45d9fe9933c47 Mon Sep 17 00:00:00 2001 From: sfam Date: Fri, 15 Jan 2016 18:14:46 +0000 Subject: [PATCH 6/6] fix import BinarySensorDevice --- homeassistant/components/binary_sensor/rpi_gpio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/binary_sensor/rpi_gpio.py b/homeassistant/components/binary_sensor/rpi_gpio.py index 39a7edecb79..2bb50fec766 100644 --- a/homeassistant/components/binary_sensor/rpi_gpio.py +++ b/homeassistant/components/binary_sensor/rpi_gpio.py @@ -9,7 +9,7 @@ https://home-assistant.io/components/binary_sensor.rpi_gpio/ import logging import homeassistant.components.rpi_gpio as rpi_gpio -from homeassistant.helpers.entity import Entity +from homeassistant.components.binary_sensor import BinarySensorDevice from homeassistant.const import (DEVICE_DEFAULT_NAME) DEFAULT_PULL_MODE = "UP"