diff --git a/.coveragerc b/.coveragerc index dc76159c045..adb3c59765e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -41,6 +41,9 @@ 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/browser.py @@ -101,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 @@ -117,13 +119,13 @@ 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 homeassistant/components/thermostat/homematic.py homeassistant/components/thermostat/honeywell.py homeassistant/components/thermostat/nest.py + homeassistant/components/thermostat/proliphix.py homeassistant/components/thermostat/radiotherm.py diff --git a/homeassistant/components/alarm_control_panel/alarmdotcom.py b/homeassistant/components/alarm_control_panel/alarmdotcom.py index f53f7bc3227..7f76680feb7 100644 --- a/homeassistant/components/alarm_control_panel/alarmdotcom.py +++ b/homeassistant/components/alarm_control_panel/alarmdotcom.py @@ -1,9 +1,10 @@ """ homeassistant.components.alarm_control_panel.alarmdotcom -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Interfaces with Verisure alarm control panel. + For more details about this platform, please refer to the documentation at -https://home-assistant.io/components/alarmdotcom/ +https://home-assistant.io/components/alarm_control_panel.alarmdotcom/ """ import logging @@ -24,7 +25,7 @@ DEFAULT_NAME = 'Alarm.com' def setup_platform(hass, config, add_devices, discovery_info=None): - """ Setup Alarm.com control panel """ + """ Setup an Alarm.com control panel. """ username = config.get(CONF_USERNAME) password = config.get(CONF_PASSWORD) @@ -43,7 +44,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): # pylint: disable=too-many-arguments, too-many-instance-attributes # pylint: disable=abstract-method class AlarmDotCom(alarm.AlarmControlPanel): - """ Represents a Alarm.com status within HA """ + """ Represents a Alarm.com status. """ def __init__(self, hass, name, code, username, password): from pyalarmdotcom.pyalarmdotcom import Alarmdotcom @@ -64,11 +65,12 @@ class AlarmDotCom(alarm.AlarmControlPanel): @property def code_format(self): - """ One or more characters if code is defined """ + """ One or more characters if code is defined. """ return None if self._code is None else '.+' @property def state(self): + """ Returns the state of the device. """ if self._alarm.state == 'Disarmed': return STATE_ALARM_DISARMED elif self._alarm.state == 'Armed Stay': @@ -79,6 +81,7 @@ class AlarmDotCom(alarm.AlarmControlPanel): return STATE_UNKNOWN def alarm_disarm(self, code=None): + """ Send disarm command. """ if not self._validate_code(code, 'arming home'): return from pyalarmdotcom.pyalarmdotcom import Alarmdotcom @@ -88,6 +91,7 @@ class AlarmDotCom(alarm.AlarmControlPanel): self.update_ha_state() def alarm_arm_home(self, code=None): + """ Send arm home command. """ if not self._validate_code(code, 'arming home'): return from pyalarmdotcom.pyalarmdotcom import Alarmdotcom @@ -97,6 +101,7 @@ class AlarmDotCom(alarm.AlarmControlPanel): self.update_ha_state() def alarm_arm_away(self, code=None): + """ Send arm away command. """ if not self._validate_code(code, 'arming home'): return from pyalarmdotcom.pyalarmdotcom import Alarmdotcom diff --git a/homeassistant/components/binary_sensor/rpi_gpio.py b/homeassistant/components/binary_sensor/rpi_gpio.py new file mode 100644 index 00000000000..2bb50fec766 --- /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 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.components.binary_sensor import BinarySensorDevice +from homeassistant.const import (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 devices. """ + + 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(BinarySensorDevice): + """ Represents a binary sensor that uses Raspberry Pi GPIO. """ + 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 is_on(self): + """ Returns the state of the entity. """ + return self._state != self._invert_logic diff --git a/homeassistant/components/device_tracker/locative.py b/homeassistant/components/device_tracker/locative.py index e7532d1075d..11884829600 100644 --- a/homeassistant/components/device_tracker/locative.py +++ b/homeassistant/components/device_tracker/locative.py @@ -49,10 +49,9 @@ def _handle_get_api_locative(hass, see, handler, path_match, data): handler.write_text("Setting location to {}".format(location_name)) elif direction == 'exit': - current_state = hass.states.get( - "{}.{}".format(DOMAIN, device)).state + current_state = hass.states.get("{}.{}".format(DOMAIN, device)) - if current_state == location_name: + if current_state is None or current_state.state == location_name: see(dev_id=device, location_name=STATE_NOT_HOME) handler.write_text("Setting location to not home") else: diff --git a/homeassistant/components/frontend/version.py b/homeassistant/components/frontend/version.py index bc2dc90bdf9..b8a31e418ca 100644 --- a/homeassistant/components/frontend/version.py +++ b/homeassistant/components/frontend/version.py @@ -1,2 +1,2 @@ """ DO NOT MODIFY. Auto-generated by build_frontend script """ -VERSION = "fe71771b9b24b0fb72a56e775c3e1112" +VERSION = "1003c31441ec44b3db84b49980f736a7" diff --git a/homeassistant/components/frontend/www_static/frontend.html b/homeassistant/components/frontend/www_static/frontend.html index da7c887cda3..1816b922342 100644 --- a/homeassistant/components/frontend/www_static/frontend.html +++ b/homeassistant/components/frontend/www_static/frontend.html @@ -3607,6 +3607,7 @@ case"touchend":return this.addPointerListenerEnd(t,e,i,n);case"touchmove":return iron-image { border-radius: 50%; + background-color: #FFFFFF; } ha-state-icon { @@ -5102,7 +5103,7 @@ case"touchend":return this.addPointerListenerEnd(t,e,i,n);case"touchmove":return border-radius: 50%; }