diff --git a/homeassistant/auth/__init__.py b/homeassistant/auth/__init__.py index 3377bb2a6aa0d..bb90f2964687b 100644 --- a/homeassistant/auth/__init__.py +++ b/homeassistant/auth/__init__.py @@ -170,8 +170,7 @@ async def async_get_or_create_user(self, credentials: models.Credentials) \ user = await self.async_get_user_by_credentials(credentials) if user is None: raise ValueError('Unable to find the user.') - else: - return user + return user auth_provider = self._async_get_auth_provider(credentials) diff --git a/homeassistant/components/bloomsky/__init__.py b/homeassistant/components/bloomsky/__init__.py index a42eb34004be9..7f9249296626f 100644 --- a/homeassistant/components/bloomsky/__init__.py +++ b/homeassistant/components/bloomsky/__init__.py @@ -66,7 +66,7 @@ def refresh_devices(self): self.API_URL, headers={AUTHORIZATION: self._api_key}, timeout=10) if response.status_code == 401: raise RuntimeError("Invalid API_KEY") - elif response.status_code != 200: + if response.status_code != 200: _LOGGER.error("Invalid HTTP response: %s", response.status_code) return # Create dictionary keyed off of the device unique id diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py index 7d8449197dec7..1263811aae76d 100644 --- a/homeassistant/components/device_tracker/__init__.py +++ b/homeassistant/components/device_tracker/__init__.py @@ -291,7 +291,7 @@ async def async_see( """ if mac is None and dev_id is None: raise HomeAssistantError('Neither mac or device id passed in') - elif mac is not None: + if mac is not None: mac = str(mac).upper() device = self.mac_to_dev.get(mac) if not device: diff --git a/homeassistant/components/device_tracker/ubus.py b/homeassistant/components/device_tracker/ubus.py index 94e3b407d13ab..96f2f60c1e524 100644 --- a/homeassistant/components/device_tracker/ubus.py +++ b/homeassistant/components/device_tracker/ubus.py @@ -216,8 +216,7 @@ def _req_json_rpc(url, session_id, rpcmethod, subsystem, method, **params): if 'message' in response['error'] and \ response['error']['message'] == "Access denied": raise PermissionError(response['error']['message']) - else: - raise HomeAssistantError(response['error']['message']) + raise HomeAssistantError(response['error']['message']) if rpcmethod == "call": try: diff --git a/homeassistant/components/logbook/__init__.py b/homeassistant/components/logbook/__init__.py index 74a90f0f5f0ca..dbedc8c6d7048 100644 --- a/homeassistant/components/logbook/__init__.py +++ b/homeassistant/components/logbook/__init__.py @@ -366,8 +366,7 @@ def _get_related_entity_ids(session, entity_filter): if tryno == RETRIES - 1: raise - else: - time.sleep(QUERY_RETRY_WAIT) + time.sleep(QUERY_RETRY_WAIT) def _generate_filter_from_config(config): diff --git a/homeassistant/components/media_player/bluesound.py b/homeassistant/components/media_player/bluesound.py index c6a8c51ca58bf..b25916c7f66d9 100644 --- a/homeassistant/components/media_player/bluesound.py +++ b/homeassistant/components/media_player/bluesound.py @@ -345,9 +345,8 @@ async def send_bluesound_command( if raise_timeout: _LOGGER.info("Timeout: %s", self.host) raise - else: - _LOGGER.debug("Failed communicating: %s", self.host) - return None + _LOGGER.debug("Failed communicating: %s", self.host) + return None return data diff --git a/homeassistant/components/nest/local_auth.py b/homeassistant/components/nest/local_auth.py index 393a36e4a9ce2..5cb63956aeaab 100644 --- a/homeassistant/components/nest/local_auth.py +++ b/homeassistant/components/nest/local_auth.py @@ -41,6 +41,5 @@ async def resolve_auth_code(hass, client_id, client_secret, code): except AuthorizationError as err: if err.response.status_code == 401: raise config_flow.CodeInvalid() - else: - raise config_flow.NestAuthError('Unknown error: {} ({})'.format( - err, err.response.status_code)) + raise config_flow.NestAuthError('Unknown error: {} ({})'.format( + err, err.response.status_code)) diff --git a/homeassistant/components/notify/nfandroidtv.py b/homeassistant/components/notify/nfandroidtv.py index faf5e90e0166c..f99d97574b4eb 100644 --- a/homeassistant/components/notify/nfandroidtv.py +++ b/homeassistant/components/notify/nfandroidtv.py @@ -248,7 +248,7 @@ def load_file(self, url=None, local_path=None, username=None, req = requests.get(url, timeout=DEFAULT_TIMEOUT) return req.content - elif local_path is not None: + if local_path is not None: # Check whether path is whitelisted in configuration.yaml if self.is_allowed_path(local_path): return open(local_path, "rb") diff --git a/homeassistant/components/notify/pushsafer.py b/homeassistant/components/notify/pushsafer.py index 443d56521c1e2..94dc08a811385 100644 --- a/homeassistant/components/notify/pushsafer.py +++ b/homeassistant/components/notify/pushsafer.py @@ -149,8 +149,7 @@ def load_from_url(self, url=None, username=None, password=None, auth=None): response = requests.get(url, timeout=CONF_TIMEOUT) return self.get_base64(response.content, response.headers['content-type']) - else: - _LOGGER.warning("url not found in param") + _LOGGER.warning("url not found in param") return None diff --git a/homeassistant/components/notify/slack.py b/homeassistant/components/notify/slack.py index 8e23c9f4fa0fd..961f671203ffd 100644 --- a/homeassistant/components/notify/slack.py +++ b/homeassistant/components/notify/slack.py @@ -152,7 +152,7 @@ def load_file(self, url=None, local_path=None, username=None, req = requests.get(url, timeout=CONF_TIMEOUT) return req.content - elif local_path: + if local_path: # Check whether path is whitelisted in configuration.yaml if self.is_allowed_path(local_path): return open(local_path, 'rb') diff --git a/homeassistant/components/panel_custom/__init__.py b/homeassistant/components/panel_custom/__init__.py index f6602169eb21f..2fce5d9857c99 100644 --- a/homeassistant/components/panel_custom/__init__.py +++ b/homeassistant/components/panel_custom/__init__.py @@ -81,7 +81,7 @@ async def async_register_panel( """Register a new custom panel.""" if js_url is None and html_url is None and module_url is None: raise ValueError('Either js_url, module_url or html_url is required.') - elif (js_url and html_url) or (module_url and html_url): + if (js_url and html_url) or (module_url and html_url): raise ValueError('Pass in only one of JS url, Module url or HTML url.') if config is not None and not isinstance(config, dict): diff --git a/homeassistant/components/python_script/__init__.py b/homeassistant/components/python_script/__init__.py index 3d0952b89fbac..d639b638033dc 100644 --- a/homeassistant/components/python_script/__init__.py +++ b/homeassistant/components/python_script/__init__.py @@ -125,13 +125,13 @@ def protected_getattr(obj, name, default=None): # pylint: disable=too-many-boolean-expressions if name.startswith('async_'): raise ScriptError("Not allowed to access async methods") - elif (obj is hass and name not in ALLOWED_HASS or - obj is hass.bus and name not in ALLOWED_EVENTBUS or - obj is hass.states and name not in ALLOWED_STATEMACHINE or - obj is hass.services and name not in ALLOWED_SERVICEREGISTRY or - obj is dt_util and name not in ALLOWED_DT_UTIL or - obj is datetime and name not in ALLOWED_DATETIME or - isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME): + if (obj is hass and name not in ALLOWED_HASS or + obj is hass.bus and name not in ALLOWED_EVENTBUS or + obj is hass.states and name not in ALLOWED_STATEMACHINE or + obj is hass.services and name not in ALLOWED_SERVICEREGISTRY or + obj is dt_util and name not in ALLOWED_DT_UTIL or + obj is datetime and name not in ALLOWED_DATETIME or + isinstance(obj, TimeWrapper) and name not in ALLOWED_TIME): raise ScriptError("Not allowed to access {}.{}".format( obj.__class__.__name__, name)) diff --git a/homeassistant/components/recorder/util.py b/homeassistant/components/recorder/util.py index c6390e5d8e2c7..449f910fda961 100644 --- a/homeassistant/components/recorder/util.py +++ b/homeassistant/components/recorder/util.py @@ -76,5 +76,4 @@ def execute(qry): if tryno == RETRIES - 1: raise - else: - time.sleep(QUERY_RETRY_WAIT) + time.sleep(QUERY_RETRY_WAIT) diff --git a/homeassistant/components/sensor/currencylayer.py b/homeassistant/components/sensor/currencylayer.py index bbc63633c5166..9b7186e8e0952 100644 --- a/homeassistant/components/sensor/currencylayer.py +++ b/homeassistant/components/sensor/currencylayer.py @@ -119,10 +119,9 @@ def update(self): self._resource, params=self._parameters, timeout=10) if 'error' in result.json(): raise ValueError(result.json()['error']['info']) - else: - self.data = result.json()['quotes'] - _LOGGER.debug("Currencylayer data updated: %s", - result.json()['timestamp']) + self.data = result.json()['quotes'] + _LOGGER.debug("Currencylayer data updated: %s", + result.json()['timestamp']) except ValueError as err: _LOGGER.error("Check Currencylayer API %s", err.args) self.data = None diff --git a/homeassistant/components/sensor/starlingbank.py b/homeassistant/components/sensor/starlingbank.py index 84b30daa2e9e3..9cb576707402e 100644 --- a/homeassistant/components/sensor/starlingbank.py +++ b/homeassistant/components/sensor/starlingbank.py @@ -44,7 +44,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None): """Set up the Sterling Bank sensor platform.""" - from starlingbank import StarlingAccount + from starlingbank import StarlingAccount # pylint: disable=syntax-error sensors = [] for account in config[CONF_ACCOUNTS]: diff --git a/homeassistant/components/switch/switchmate.py b/homeassistant/components/switch/switchmate.py index 5289ca6ec1ba5..60497e0207b70 100644 --- a/homeassistant/components/switch/switchmate.py +++ b/homeassistant/components/switch/switchmate.py @@ -34,10 +34,10 @@ def setup_platform(hass, config, add_entities, discovery_info=None) -> None: name = config.get(CONF_NAME) mac_addr = config[CONF_MAC] flip_on_off = config[CONF_FLIP_ON_OFF] - add_entities([Switchmate(mac_addr, name, flip_on_off)], True) + add_entities([SwitchmateEntity(mac_addr, name, flip_on_off)], True) -class Switchmate(SwitchDevice): +class SwitchmateEntity(SwitchDevice): """Representation of a Switchmate.""" def __init__(self, mac, name, flip_on_off) -> None: diff --git a/homeassistant/components/telegram_bot/__init__.py b/homeassistant/components/telegram_bot/__init__.py index 18f206541dfa6..c55b27e97a6b9 100644 --- a/homeassistant/components/telegram_bot/__init__.py +++ b/homeassistant/components/telegram_bot/__init__.py @@ -628,7 +628,7 @@ def process_message(self, data): self.hass.bus.async_fire(event, event_data) return True - elif ATTR_CALLBACK_QUERY in data: + if ATTR_CALLBACK_QUERY in data: event = EVENT_TELEGRAM_CALLBACK data = data.get(ATTR_CALLBACK_QUERY) message_ok, event_data = self._get_message_data(data) @@ -642,6 +642,6 @@ def process_message(self, data): self.hass.bus.async_fire(event, event_data) return True - else: - _LOGGER.warning("Message with unknown data received: %s", data) - return True + + _LOGGER.warning("Message with unknown data received: %s", data) + return True diff --git a/homeassistant/components/telegram_bot/polling.py b/homeassistant/components/telegram_bot/polling.py index 5bca4321a5f22..9936b69098568 100644 --- a/homeassistant/components/telegram_bot/polling.py +++ b/homeassistant/components/telegram_bot/polling.py @@ -61,7 +61,7 @@ def __init__(self): """Initialize the messages handler instance.""" super().__init__(handler) - def check_update(self, update): + def check_update(self, update): # pylint: disable=no-self-use """Check is update valid.""" return isinstance(update, Update) diff --git a/homeassistant/components/tellduslive/config_flow.py b/homeassistant/components/tellduslive/config_flow.py index 3373e9cc2f7ca..62463bc0a9ea3 100644 --- a/homeassistant/components/tellduslive/config_flow.py +++ b/homeassistant/components/tellduslive/config_flow.py @@ -84,8 +84,7 @@ async def async_step_auth(self, user_input=None): KEY_SCAN_INTERVAL: self._scan_interval.seconds, KEY_SESSION: session, }) - else: - errors['base'] = 'auth_error' + errors['base'] = 'auth_error' try: with async_timeout.timeout(10): diff --git a/homeassistant/components/websocket_api/http.py b/homeassistant/components/websocket_api/http.py index 42c2c0a5751e3..1ab2b09d7fa6f 100644 --- a/homeassistant/components/websocket_api/http.py +++ b/homeassistant/components/websocket_api/http.py @@ -130,7 +130,7 @@ def handle_hass_stop(event): if msg.type in (WSMsgType.CLOSE, WSMsgType.CLOSING): raise Disconnect - elif msg.type != WSMsgType.TEXT: + if msg.type != WSMsgType.TEXT: disconnect_warn = 'Received non-Text message.' raise Disconnect diff --git a/homeassistant/helpers/area_registry.py b/homeassistant/helpers/area_registry.py index bc8c05ed0a67b..3fa820f835074 100644 --- a/homeassistant/helpers/area_registry.py +++ b/homeassistant/helpers/area_registry.py @@ -75,8 +75,8 @@ def async_update(self, area_id: str, name: str) -> AreaEntry: if self._async_is_registered(name): raise ValueError('Name is already in use') - else: - changes['name'] = name + + changes['name'] = name new = self.areas[area_id] = attr.evolve(old, **changes) self.async_schedule_save() diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index b5716431217f7..4bba80aa15436 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -293,7 +293,7 @@ def time_period_str(value: str) -> timedelta: """Validate and transform time offset.""" if isinstance(value, int): raise vol.Invalid('Make sure you wrap time values in quotes') - elif not isinstance(value, str): + if not isinstance(value, str): raise vol.Invalid(TIME_PERIOD_ERROR.format(value)) negative_offset = False @@ -440,7 +440,7 @@ def template(value): """Validate a jinja2 template.""" if value is None: raise vol.Invalid('template value is None') - elif isinstance(value, (list, dict, template_helper.Template)): + if isinstance(value, (list, dict, template_helper.Template)): raise vol.Invalid('template value should be a string') value = template_helper.Template(str(value)) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index c13ebe7cfab1e..dd9677f651556 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -28,11 +28,10 @@ def generate_entity_id(entity_id_format: str, name: Optional[str], if current_ids is None: if hass is None: raise ValueError("Missing required parameter currentids or hass") - else: - return run_callback_threadsafe( - hass.loop, async_generate_entity_id, entity_id_format, name, - current_ids, hass - ).result() + return run_callback_threadsafe( + hass.loop, async_generate_entity_id, entity_id_format, name, + current_ids, hass + ).result() name = (slugify(name) or slugify(DEVICE_DEFAULT_NAME)).lower() diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 9c76d244138c8..87cc4d4fd90ed 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -334,9 +334,9 @@ async def _async_add_entity(self, entity, update_before_add, if not valid_entity_id(entity.entity_id): raise HomeAssistantError( 'Invalid entity id: {}'.format(entity.entity_id)) - elif (entity.entity_id in self.entities or - entity.entity_id in self.hass.states.async_entity_ids( - self.domain)): + if (entity.entity_id in self.entities or + entity.entity_id in self.hass.states.async_entity_ids( + self.domain)): msg = 'Entity id already exists: {}'.format(entity.entity_id) if entity.unique_id is not None: msg += '. Platform {} does not generate unique IDs'.format( diff --git a/requirements_test.txt b/requirements_test.txt index 6568ca89a0716..531fb0b78f65e 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -8,7 +8,7 @@ flake8==3.7.7 mock-open==1.3.1 mypy==0.670 pydocstyle==3.0.0 -pylint==2.2.2 +pylint==2.3.0 pytest-aiohttp==0.3.0 pytest-cov==2.6.1 pytest-sugar==0.9.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 493888baeb950..267a1006d321b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -9,7 +9,7 @@ flake8==3.7.7 mock-open==1.3.1 mypy==0.670 pydocstyle==3.0.0 -pylint==2.2.2 +pylint==2.3.0 pytest-aiohttp==0.3.0 pytest-cov==2.6.1 pytest-sugar==0.9.2