Skip to content

Commit

Permalink
pylint 2.3.0 (home-assistant#21485)
Browse files Browse the repository at this point in the history
* pylint 2.3.0

* remove const

*  disable=syntax-error
  • Loading branch information
Danielhiversen authored and dmulcahey committed Feb 27, 2019
1 parent 2482816 commit 519315f
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 57 deletions.
3 changes: 1 addition & 2 deletions homeassistant/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/bloomsky/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/device_tracker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/device_tracker/ubus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/logbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/media_player/bluesound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 2 additions & 3 deletions homeassistant/components/nest/local_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
2 changes: 1 addition & 1 deletion homeassistant/components/notify/nfandroidtv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/notify/pushsafer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/notify/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/panel_custom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 7 additions & 7 deletions homeassistant/components/python_script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/recorder/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ def execute(qry):

if tryno == RETRIES - 1:
raise
else:
time.sleep(QUERY_RETRY_WAIT)
time.sleep(QUERY_RETRY_WAIT)
7 changes: 3 additions & 4 deletions homeassistant/components/sensor/currencylayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion homeassistant/components/sensor/starlingbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/switch/switchmate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/telegram_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
2 changes: 1 addition & 1 deletion homeassistant/components/telegram_bot/polling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/tellduslive/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/websocket_api/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions homeassistant/helpers/area_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/helpers/config_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/helpers/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions homeassistant/helpers/entity_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 519315f

Please sign in to comment.