From 3b7b12bbd5bc0787d71a7423da50655b171aa9e6 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 12 Jan 2016 21:53:27 -0800 Subject: [PATCH 1/3] Make Flake8 happy --- .../components/alarm_control_panel/manual.py | 3 ++- .../components/automation/numeric_state.py | 23 +++++++++--------- homeassistant/components/automation/sun.py | 24 ++++++++++++++----- homeassistant/components/automation/time.py | 4 ++-- .../components/device_tracker/snmp.py | 3 +-- .../components/device_tracker/tplink.py | 4 ++-- homeassistant/components/http.py | 12 +++++----- homeassistant/components/light/rfxtrx.py | 5 ++-- .../components/media_player/squeezebox.py | 15 ++++++------ homeassistant/components/sensor/arest.py | 4 ++-- homeassistant/components/switch/rfxtrx.py | 5 ++-- homeassistant/components/thermostat/ecobee.py | 5 ++-- 12 files changed, 60 insertions(+), 47 deletions(-) diff --git a/homeassistant/components/alarm_control_panel/manual.py b/homeassistant/components/alarm_control_panel/manual.py index 63bc989f3df..2658e005aea 100644 --- a/homeassistant/components/alarm_control_panel/manual.py +++ b/homeassistant/components/alarm_control_panel/manual.py @@ -68,7 +68,8 @@ class ManualAlarm(alarm.AlarmControlPanel): @property def state(self): """ Returns the state of the device. """ - if self._state in (STATE_ALARM_ARMED_HOME, STATE_ALARM_ARMED_AWAY) and \ + if self._state in (STATE_ALARM_ARMED_HOME, + STATE_ALARM_ARMED_AWAY) and \ self._pending_time and self._state_ts + self._pending_time > \ dt_util.utcnow(): return STATE_ALARM_PENDING diff --git a/homeassistant/components/automation/numeric_state.py b/homeassistant/components/automation/numeric_state.py index f2baf760748..61e68aa8e8e 100644 --- a/homeassistant/components/automation/numeric_state.py +++ b/homeassistant/components/automation/numeric_state.py @@ -6,6 +6,7 @@ Offers numeric state listening automation rules. For more details about this automation rule, please refer to the documentation at https://home-assistant.io/components/automation/#numeric-state-trigger """ +from functools import partial import logging from homeassistant.const import CONF_VALUE_TEMPLATE @@ -20,6 +21,14 @@ CONF_ABOVE = "above" _LOGGER = logging.getLogger(__name__) +def _renderer(hass, value_template, state): + """Render state value.""" + if value_template is None: + return state.state + + return template.render(hass, value_template, {'state': state}) + + def trigger(hass, config, action): """ Listen for state changes based on `config`. """ entity_id = config.get(CONF_ENTITY_ID) @@ -38,12 +47,7 @@ def trigger(hass, config, action): CONF_BELOW, CONF_ABOVE) return False - if value_template is not None: - renderer = lambda value: template.render(hass, - value_template, - {'state': value}) - else: - renderer = lambda value: value.state + renderer = partial(_renderer, hass, value_template) # pylint: disable=unused-argument def state_automation_listener(entity, from_s, to_s): @@ -79,12 +83,7 @@ def if_action(hass, config): CONF_BELOW, CONF_ABOVE) return None - if value_template is not None: - renderer = lambda value: template.render(hass, - value_template, - {'state': value}) - else: - renderer = lambda value: value.state + renderer = partial(_renderer, hass, value_template) def if_numeric_state(): """ Test numeric state condition. """ diff --git a/homeassistant/components/automation/sun.py b/homeassistant/components/automation/sun.py index 064f6a0a16a..0616c0a48e6 100644 --- a/homeassistant/components/automation/sun.py +++ b/homeassistant/components/automation/sun.py @@ -80,18 +80,30 @@ def if_action(hass, config): return None if before is None: - before_func = lambda: None + def before_func(): + """Return no point in time.""" + return None elif before == EVENT_SUNRISE: - before_func = lambda: sun.next_rising(hass) + before_offset + def before_func(): + """Return time before sunrise.""" + return sun.next_rising(hass) + before_offset else: - before_func = lambda: sun.next_setting(hass) + before_offset + def before_func(): + """Return time before sunset.""" + return sun.next_setting(hass) + before_offset if after is None: - after_func = lambda: None + def after_func(): + """Return no point in time.""" + return None elif after == EVENT_SUNRISE: - after_func = lambda: sun.next_rising(hass) + after_offset + def after_func(): + """Return time after sunrise.""" + return sun.next_rising(hass) + after_offset else: - after_func = lambda: sun.next_setting(hass) + after_offset + def after_func(): + """Return time after sunset.""" + return sun.next_setting(hass) + after_offset def time_if(): """ Validate time based if-condition """ diff --git a/homeassistant/components/automation/time.py b/homeassistant/components/automation/time.py index 7fc2c0d40e2..e8cf9c3b6ee 100644 --- a/homeassistant/components/automation/time.py +++ b/homeassistant/components/automation/time.py @@ -32,8 +32,8 @@ def trigger(hass, config, action): _error_time(config[CONF_AFTER], CONF_AFTER) return False hours, minutes, seconds = after.hour, after.minute, after.second - elif (CONF_HOURS in config or CONF_MINUTES in config - or CONF_SECONDS in config): + elif (CONF_HOURS in config or CONF_MINUTES in config or + CONF_SECONDS in config): hours = convert(config.get(CONF_HOURS), int) minutes = convert(config.get(CONF_MINUTES), int) seconds = convert(config.get(CONF_SECONDS), int) diff --git a/homeassistant/components/device_tracker/snmp.py b/homeassistant/components/device_tracker/snmp.py index 868f701673a..cd0e8239c38 100644 --- a/homeassistant/components/device_tracker/snmp.py +++ b/homeassistant/components/device_tracker/snmp.py @@ -105,8 +105,7 @@ class SnmpScanner(object): return if errstatus: _LOGGER.error('SNMP error: %s at %s', errstatus.prettyPrint(), - errindex and restable[-1][int(errindex)-1] - or '?') + errindex and restable[-1][int(errindex)-1] or '?') return for resrow in restable: diff --git a/homeassistant/components/device_tracker/tplink.py b/homeassistant/components/device_tracker/tplink.py index 46556b3eca4..a661dac0c1e 100755 --- a/homeassistant/components/device_tracker/tplink.py +++ b/homeassistant/components/device_tracker/tplink.py @@ -242,8 +242,8 @@ class Tplink3DeviceScanner(TplinkDeviceScanner): _LOGGER.info("Loading wireless clients...") - url = 'http://{}/cgi-bin/luci/;stok={}/admin/wireless?form=statistics' \ - .format(self.host, self.stok) + url = ('http://{}/cgi-bin/luci/;stok={}/admin/wireless?' + 'form=statistics').format(self.host, self.stok) referer = 'http://{}/webpages/index.html'.format(self.host) response = requests.post(url, diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index b7f57b0157e..35c215a8630 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -198,12 +198,12 @@ class RequestHandler(SimpleHTTPRequestHandler): "Error parsing JSON", HTTP_UNPROCESSABLE_ENTITY) return - self.authenticated = (self.server.api_password is None - or self.headers.get(HTTP_HEADER_HA_AUTH) == - self.server.api_password - or data.get(DATA_API_PASSWORD) == - self.server.api_password - or self.verify_session()) + self.authenticated = (self.server.api_password is None or + self.headers.get(HTTP_HEADER_HA_AUTH) == + self.server.api_password or + data.get(DATA_API_PASSWORD) == + self.server.api_password or + self.verify_session()) if '_METHOD' in data: method = data.pop('_METHOD') diff --git a/homeassistant/components/light/rfxtrx.py b/homeassistant/components/light/rfxtrx.py index 6132c10a99c..22bd2575242 100644 --- a/homeassistant/components/light/rfxtrx.py +++ b/homeassistant/components/light/rfxtrx.py @@ -13,8 +13,9 @@ from homeassistant.components.light import Light from homeassistant.util import slugify from homeassistant.const import ATTR_ENTITY_ID -from homeassistant.components.rfxtrx import ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID, \ - ATTR_NAME, EVENT_BUTTON_PRESSED +from homeassistant.components.rfxtrx import ( + ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID, + ATTR_NAME, EVENT_BUTTON_PRESSED) DEPENDENCIES = ['rfxtrx'] diff --git a/homeassistant/components/media_player/squeezebox.py b/homeassistant/components/media_player/squeezebox.py index d3139d52c01..4fd13e8da42 100644 --- a/homeassistant/components/media_player/squeezebox.py +++ b/homeassistant/components/media_player/squeezebox.py @@ -22,9 +22,9 @@ from homeassistant.const import ( _LOGGER = logging.getLogger(__name__) -SUPPORT_SQUEEZEBOX = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE |\ - SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | SUPPORT_SEEK |\ - SUPPORT_TURN_ON | SUPPORT_TURN_OFF +SUPPORT_SQUEEZEBOX = SUPPORT_PAUSE | SUPPORT_VOLUME_SET | \ + SUPPORT_VOLUME_MUTE | SUPPORT_PREVIOUS_TRACK | SUPPORT_NEXT_TRACK | \ + SUPPORT_SEEK | SUPPORT_TURN_ON | SUPPORT_TURN_OFF # pylint: disable=unused-argument @@ -202,11 +202,10 @@ class SqueezeBoxDevice(MediaPlayerDevice): """ Image url of current playing media. """ if 'artwork_url' in self._status: return self._status['artwork_url'] - return 'http://{server}:{port}/music/current/cover.jpg?player={player}'\ - .format( - server=self._lms.host, - port=self._lms.http_port, - player=self._id) + return ('http://{server}:{port}/music/current/cover.jpg?' + 'player={player}').format(server=self._lms.host, + port=self._lms.http_port, + player=self._id) @property def media_title(self): diff --git a/homeassistant/components/sensor/arest.py b/homeassistant/components/sensor/arest.py index 298c9b8cb79..dd9281c484a 100644 --- a/homeassistant/components/sensor/arest.py +++ b/homeassistant/components/sensor/arest.py @@ -11,8 +11,8 @@ import logging import requests -from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, \ - DEVICE_DEFAULT_NAME +from homeassistant.const import (ATTR_UNIT_OF_MEASUREMENT, CONF_VALUE_TEMPLATE, + DEVICE_DEFAULT_NAME) from homeassistant.exceptions import TemplateError from homeassistant.helpers.entity import Entity from homeassistant.util import template, Throttle diff --git a/homeassistant/components/switch/rfxtrx.py b/homeassistant/components/switch/rfxtrx.py index 69e08e7d129..84f4df82b1f 100644 --- a/homeassistant/components/switch/rfxtrx.py +++ b/homeassistant/components/switch/rfxtrx.py @@ -13,8 +13,9 @@ from homeassistant.components.switch import SwitchDevice from homeassistant.util import slugify from homeassistant.const import ATTR_ENTITY_ID -from homeassistant.components.rfxtrx import ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID, \ - ATTR_NAME, EVENT_BUTTON_PRESSED +from homeassistant.components.rfxtrx import ( + ATTR_STATE, ATTR_FIREEVENT, ATTR_PACKETID, + ATTR_NAME, EVENT_BUTTON_PRESSED) DEPENDENCIES = ['rfxtrx'] diff --git a/homeassistant/components/thermostat/ecobee.py b/homeassistant/components/thermostat/ecobee.py index 30221689274..0b4e14f36b7 100644 --- a/homeassistant/components/thermostat/ecobee.py +++ b/homeassistant/components/thermostat/ecobee.py @@ -46,8 +46,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None): return data = ecobee.NETWORK hold_temp = discovery_info['hold_temp'] - _LOGGER.info("Loading ecobee thermostat component with hold_temp set to " - + str(hold_temp)) + _LOGGER.info( + "Loading ecobee thermostat component with hold_temp set to %s", + hold_temp) add_devices(Thermostat(data, index, hold_temp) for index in range(len(data.ecobee.thermostats))) From 60f40800c4e2f54b1739caf7795c7f64d9279ad1 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 12 Jan 2016 21:56:09 -0800 Subject: [PATCH 2/3] Use mock HA for locative tests --- tests/components/device_tracker/test_locative.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/components/device_tracker/test_locative.py b/tests/components/device_tracker/test_locative.py index b86f24455de..619fe929ac7 100644 --- a/tests/components/device_tracker/test_locative.py +++ b/tests/components/device_tracker/test_locative.py @@ -11,10 +11,10 @@ from unittest.mock import patch import requests from homeassistant import bootstrap, const -import homeassistant.core as ha import homeassistant.components.device_tracker as device_tracker import homeassistant.components.http as http -import homeassistant.components.zone as zone + +from tests.common import get_test_home_assistant SERVER_PORT = 8126 HTTP_BASE_URL = "http://127.0.0.1:{}".format(SERVER_PORT) @@ -34,7 +34,7 @@ def setUpModule(mock_get_local_ip): # pylint: disable=invalid-name """ Initalizes a Home Assistant server. """ global hass - hass = ha.HomeAssistant() + hass = get_test_home_assistant() # Set up server bootstrap.setup_component(hass, http.DOMAIN, { From 9cdf84dacf2b0010d2e2c17fa886805503f15963 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 12 Jan 2016 21:57:43 -0800 Subject: [PATCH 3/3] Update flake8 and pylint versions --- requirements_test.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_test.txt b/requirements_test.txt index 679c0e99ce5..616c49c5ae4 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,5 +1,5 @@ -flake8>=2.5.0 -pylint>=1.5.1 +flake8>=2.5.1 +pylint>=1.5.3 coveralls>=1.1 pytest>=2.6.4 pytest-cov>=2.2.0