From d2bbc6ef705ffdc30f6a98070a8a54435a987eae Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 18 Nov 2016 21:47:59 -0800 Subject: [PATCH] Upgrade linter (#4461) --- homeassistant/components/automation/__init__.py | 1 + homeassistant/components/device_tracker/actiontec.py | 1 + homeassistant/components/device_tracker/asuswrt.py | 1 + .../components/device_tracker/nmap_tracker.py | 1 + homeassistant/components/http.py | 1 + homeassistant/components/input_slider.py | 1 + homeassistant/components/media_player/yamaha.py | 2 +- homeassistant/components/mqtt/__init__.py | 1 + homeassistant/components/rfxtrx.py | 1 + homeassistant/config.py | 1 + homeassistant/helpers/config_validation.py | 1 + homeassistant/helpers/template.py | 1 + homeassistant/util/yaml.py | 1 + requirements_test.txt | 2 +- script/fingerprint_frontend.py | 1 + script/gen_requirements_all.py | 1 + script/update_mdi.py | 1 + tests/components/notify/test_apns.py | 12 ++++++++---- tests/conftest.py | 1 + tests/helpers/test_config_validation.py | 2 +- .../custom_components/device_tracker/test.py | 1 + 21 files changed, 28 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index c49bc15ff644b4..9ff2fbd878a8c1 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -66,6 +66,7 @@ def _platform_validator(config): return getattr(platform, 'TRIGGER_SCHEMA')(config) + _TRIGGER_SCHEMA = vol.All( cv.ensure_list, [ diff --git a/homeassistant/components/device_tracker/actiontec.py b/homeassistant/components/device_tracker/actiontec.py index a4804848f4af58..9583237a9128c9 100644 --- a/homeassistant/components/device_tracker/actiontec.py +++ b/homeassistant/components/device_tracker/actiontec.py @@ -42,6 +42,7 @@ def get_scanner(hass, config): scanner = ActiontecDeviceScanner(config[DOMAIN]) return scanner if scanner.success_init else None + Device = namedtuple("Device", ["mac", "ip", "last_update"]) diff --git a/homeassistant/components/device_tracker/asuswrt.py b/homeassistant/components/device_tracker/asuswrt.py index 390bebd80c8ba0..2eced1b4dd4384 100644 --- a/homeassistant/components/device_tracker/asuswrt.py +++ b/homeassistant/components/device_tracker/asuswrt.py @@ -93,6 +93,7 @@ def get_scanner(hass, config): return scanner if scanner.success_init else None + AsusWrtResult = namedtuple('AsusWrtResult', 'neighbors leases arp nvram') diff --git a/homeassistant/components/device_tracker/nmap_tracker.py b/homeassistant/components/device_tracker/nmap_tracker.py index e8a6f2b737111a..ec5a4f73b5d34d 100644 --- a/homeassistant/components/device_tracker/nmap_tracker.py +++ b/homeassistant/components/device_tracker/nmap_tracker.py @@ -43,6 +43,7 @@ def get_scanner(hass, config): return scanner if scanner.success_init else None + Device = namedtuple('Device', ['mac', 'name', 'ip', 'last_update']) diff --git a/homeassistant/components/http.py b/homeassistant/components/http.py index d69080a8a4315b..a008a3f4db62bb 100644 --- a/homeassistant/components/http.py +++ b/homeassistant/components/http.py @@ -222,6 +222,7 @@ def send(self, request, filepath): return resp + _GZIP_FILE_SENDER = GzipFileSender() diff --git a/homeassistant/components/input_slider.py b/homeassistant/components/input_slider.py index e425cd4e3e4e43..eccffb5ae29cc6 100644 --- a/homeassistant/components/input_slider.py +++ b/homeassistant/components/input_slider.py @@ -51,6 +51,7 @@ def _cv_input_slider(cfg): cfg[CONF_INITIAL] = state return cfg + CONFIG_SCHEMA = vol.Schema({ DOMAIN: vol.Schema({ cv.slug: vol.All({ diff --git a/homeassistant/components/media_player/yamaha.py b/homeassistant/components/media_player/yamaha.py index 68c491d7a24430..05f60cf06d81df 100644 --- a/homeassistant/components/media_player/yamaha.py +++ b/homeassistant/components/media_player/yamaha.py @@ -23,7 +23,7 @@ _LOGGER = logging.getLogger(__name__) SUPPORT_YAMAHA = SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE | \ - SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE + SUPPORT_TURN_ON | SUPPORT_TURN_OFF | SUPPORT_SELECT_SOURCE CONF_SOURCE_NAMES = 'source_names' CONF_SOURCE_IGNORE = 'source_ignore' diff --git a/homeassistant/components/mqtt/__init__.py b/homeassistant/components/mqtt/__init__.py index 37fc13d9a0e829..87c1a783e6e0a3 100644 --- a/homeassistant/components/mqtt/__init__.py +++ b/homeassistant/components/mqtt/__init__.py @@ -78,6 +78,7 @@ def valid_publish_topic(value): """Validate that we can publish using this MQTT topic.""" return valid_subscribe_topic(value, invalid_chars='#+\0') + _VALID_QOS_SCHEMA = vol.All(vol.Coerce(int), vol.In([0, 1, 2])) _HBMQTT_CONFIG_SCHEMA = vol.Schema(dict) diff --git a/homeassistant/components/rfxtrx.py b/homeassistant/components/rfxtrx.py index d026002e4089f0..f8a4f29738f6d4 100644 --- a/homeassistant/components/rfxtrx.py +++ b/homeassistant/components/rfxtrx.py @@ -94,6 +94,7 @@ def valid_sensor(value): def _valid_light_switch(value): return _valid_device(value, "light_switch") + DEVICE_SCHEMA = vol.Schema({ vol.Required(ATTR_NAME): cv.string, vol.Optional(ATTR_FIREEVENT, default=False): cv.boolean, diff --git a/homeassistant/config.py b/homeassistant/config.py index d56027e20f4506..ba8cbeba3ee2f4 100644 --- a/homeassistant/config.py +++ b/homeassistant/config.py @@ -93,6 +93,7 @@ def _valid_customize(value): return value + CORE_CONFIG_SCHEMA = vol.Schema({ CONF_NAME: vol.Coerce(str), CONF_LATITUDE: cv.latitude, diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 9598c57a7b2112..787d04a37870b6 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -305,6 +305,7 @@ def time_zone(value): 'Invalid time zone passed in. Valid options can be found here: ' 'http://en.wikipedia.org/wiki/List_of_tz_database_time_zones') + weekdays = vol.All(ensure_list, [vol.In(WEEKDAYS)]) diff --git a/homeassistant/helpers/template.py b/homeassistant/helpers/template.py index dac568439e4d32..d3f49c003c8ebd 100644 --- a/homeassistant/helpers/template.py +++ b/homeassistant/helpers/template.py @@ -417,6 +417,7 @@ def is_safe_callable(self, obj): """Test if callback is safe.""" return isinstance(obj, AllStates) or super().is_safe_callable(obj) + ENV = TemplateEnvironment() ENV.filters['round'] = forgiving_round ENV.filters['multiply'] = multiply diff --git a/homeassistant/util/yaml.py b/homeassistant/util/yaml.py index a91130338f561c..1307cc1a287ffb 100644 --- a/homeassistant/util/yaml.py +++ b/homeassistant/util/yaml.py @@ -249,6 +249,7 @@ def _secret_yaml(loader: SafeLineLoader, _LOGGER.error('Secret %s not defined.', node.value) raise HomeAssistantError(node.value) + yaml.SafeLoader.add_constructor('!include', _include_yaml) yaml.SafeLoader.add_constructor(yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, _ordered_dict) diff --git a/requirements_test.txt b/requirements_test.txt index 19a70665b56a7c..784631867cecea 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -1,7 +1,7 @@ # linters such as flake8 and pylint should be pinned, as new releases # make new things fail. Manually update these pins when pulling in a # new version -flake8==3.0.4 +flake8==3.2.0 pylint==1.6.4 mypy-lang==0.4.5 pydocstyle==1.1.1 diff --git a/script/fingerprint_frontend.py b/script/fingerprint_frontend.py index 09560cee0f0b41..e04f3eefe6a0b9 100755 --- a/script/fingerprint_frontend.py +++ b/script/fingerprint_frontend.py @@ -34,5 +34,6 @@ def fingerprint(): with open(fingerprint_file, 'w') as fp: fp.write(result) + if __name__ == '__main__': fingerprint() diff --git a/script/gen_requirements_all.py b/script/gen_requirements_all.py index e16ee5996de34d..f4258ea825b02c 100755 --- a/script/gen_requirements_all.py +++ b/script/gen_requirements_all.py @@ -138,5 +138,6 @@ def main(): write_file(data) + if __name__ == '__main__': main() diff --git a/script/update_mdi.py b/script/update_mdi.py index 135b2be2046519..af9ee26c949473 100755 --- a/script/update_mdi.py +++ b/script/update_mdi.py @@ -63,5 +63,6 @@ def main(): print('Updated to latest version') + if __name__ == '__main__': main() diff --git a/tests/components/notify/test_apns.py b/tests/components/notify/test_apns.py index 7103b6cdc8b24b..8be04de9b230a1 100644 --- a/tests/components/notify/test_apns.py +++ b/tests/components/notify/test_apns.py @@ -184,8 +184,10 @@ def test_update_existing_device_with_tracking_id(self): devices_path = hass.config.path('test_app_apns.yaml') with open(devices_path, 'w+') as out: - out.write('1234: {name: test device 1, tracking_device_id: tracking123}\n') # nopep8 - out.write('5678: {name: test device 2, tracking_device_id: tracking456}\n') # nopep8 + out.write('1234: {name: test device 1, ' + 'tracking_device_id: tracking123}\n') + out.write('5678: {name: test device 2, ' + 'tracking_device_id: tracking456}\n') notify.setup(hass, config) self.assertTrue(hass.services.call('apns', @@ -293,8 +295,10 @@ def test_send_with_state(self, mock_client): devices_path = hass.config.path('test_app_apns.yaml') with open(devices_path, 'w+') as out: - out.write('1234: {name: test device 1, tracking_device_id: tracking123}\n') # nopep8 - out.write('5678: {name: test device 2, tracking_device_id: tracking456}\n') # nopep8 + out.write('1234: {name: test device 1, ' + 'tracking_device_id: tracking123}\n') + out.write('5678: {name: test device 2, ' + 'tracking_device_id: tracking456}\n') notify_service = ApnsNotificationService( hass, diff --git a/tests/conftest.py b/tests/conftest.py index 815765a8ed2228..54f5404d72d364 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -29,6 +29,7 @@ def guard_func(*args, **kwargs): return guard_func + # Guard a few functions that would make network connections location.detect_location_info = test_real(location.detect_location_info) location.elevation = test_real(location.elevation) diff --git a/tests/helpers/test_config_validation.py b/tests/helpers/test_config_validation.py index 7d9030bdc96008..072482673d6345 100644 --- a/tests/helpers/test_config_validation.py +++ b/tests/helpers/test_config_validation.py @@ -341,7 +341,7 @@ def test_template_complex(): 1, 'Hello', '{{ beer }}', '{% if 1 == 1 %}Hello{% else %}World{% endif %}', - {'test': 1, 'test': '{{ beer }}'}, + {'test': 1, 'test2': '{{ beer }}'}, ['{{ beer }}', 1] ): schema(value) diff --git a/tests/testing_config/custom_components/device_tracker/test.py b/tests/testing_config/custom_components/device_tracker/test.py index 7db54c6fc2b039..70ec0c4cef99d9 100644 --- a/tests/testing_config/custom_components/device_tracker/test.py +++ b/tests/testing_config/custom_components/device_tracker/test.py @@ -36,4 +36,5 @@ def get_device_name(self, device): """ return None if device == 'DEV1' else device.lower() + SCANNER = MockScanner()