Narrow scope of various pylint inline disables (#15364)

* Narrow scope of various pylint inline disables

* Whitespace tweaks
This commit is contained in:
Ville Skyttä 2018-10-10 13:17:11 +03:00 committed by Paulus Schoutsen
parent 78c38749ab
commit 707b7c202d
30 changed files with 52 additions and 75 deletions

View File

@ -49,10 +49,9 @@ def setup(hass, config):
# It doesn't really matter why we're not able to get the status, just that
# we can't.
# pylint: disable=broad-except
try:
DATA.update(no_throttle=True)
except Exception:
except Exception: # pylint: disable=broad-except
_LOGGER.exception("Failure while testing APCUPSd status retrieval.")
return False
return True

View File

@ -68,6 +68,7 @@ class GoogleCalendarData:
self.event = None
def _prepare_query(self):
# pylint: disable=import-error
from httplib2 import ServerNotFoundError
try:

View File

@ -53,14 +53,13 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
add_entities(devices)
# pylint: disable=import-error
class EQ3BTSmartThermostat(ClimateDevice):
"""Representation of an eQ-3 Bluetooth Smart thermostat."""
def __init__(self, _mac, _name):
"""Initialize the thermostat."""
# We want to avoid name clash with this module.
import eq3bt as eq3
import eq3bt as eq3 # pylint: disable=import-error
self.modes = {
eq3.Mode.Open: STATE_ON,
@ -176,7 +175,7 @@ class EQ3BTSmartThermostat(ClimateDevice):
def update(self):
"""Update the data from the thermostat."""
from bluepy.btle import BTLEException
from bluepy.btle import BTLEException # pylint: disable=import-error
try:
self._thermostat.update()
except BTLEException as ex:

View File

@ -4,8 +4,6 @@ Support for Z-Wave cover components.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/cover.zwave/
"""
# Because we do not compile openzwave on CI
# pylint: disable=import-error
import logging
from homeassistant.components.cover import (
DOMAIN, SUPPORT_OPEN, SUPPORT_CLOSE, ATTR_POSITION)

View File

@ -43,8 +43,7 @@ class FritzBoxScanner(DeviceScanner):
self.password = config[CONF_PASSWORD]
self.success_init = True
# pylint: disable=import-error
import fritzconnection as fc
import fritzconnection as fc # pylint: disable=import-error
# Establish a connection to the FRITZ!Box.
try:

View File

@ -86,10 +86,9 @@ class UnifiDeviceScanner(DeviceScanner):
def _disconnect(self):
"""Disconnect the current SSH connection."""
# pylint: disable=broad-except
try:
self.ssh.logout()
except Exception:
except Exception: # pylint: disable=broad-except
pass
finally:
self.ssh = None

View File

@ -144,8 +144,7 @@ class GraphiteFeeder(threading.Thread):
try:
self._report_attributes(
event.data['entity_id'], event.data['new_state'])
# pylint: disable=broad-except
except Exception:
except Exception: # pylint: disable=broad-except
# Catch this so we can avoid the thread dying and
# make it visible.
_LOGGER.exception("Failed to process STATE_CHANGED event")

View File

@ -65,8 +65,7 @@ def homekit_http_send(self, message_body=None, encode_chunked=False):
def get_serial(accessory):
"""Obtain the serial number of a HomeKit device."""
# pylint: disable=import-error
import homekit
import homekit # pylint: disable=import-error
for service in accessory['services']:
if homekit.ServicesTypes.get_short(service['type']) != \
'accessory-information':
@ -85,8 +84,7 @@ class HKDevice():
def __init__(self, hass, host, port, model, hkid, config_num, config):
"""Initialise a generic HomeKit device."""
# pylint: disable=import-error
import homekit
import homekit # pylint: disable=import-error
_LOGGER.info("Setting up Homekit device %s", model)
self.hass = hass
@ -132,8 +130,7 @@ class HKDevice():
def accessory_setup(self):
"""Handle setup of a HomeKit accessory."""
# pylint: disable=import-error
import homekit
import homekit # pylint: disable=import-error
try:
data = self.get_json('/accessories')
@ -185,8 +182,7 @@ class HKDevice():
def device_config_callback(self, callback_data):
"""Handle initial pairing."""
# pylint: disable=import-error
import homekit
import homekit # pylint: disable=import-error
pairing_id = str(uuid.uuid4())
code = callback_data.get('code').strip()
try:

View File

@ -778,8 +778,7 @@ class HMDevice(Entity):
# Link events from pyhomematic
self._subscribe_homematic_events()
self._available = not self._hmdevice.UNREACH
# pylint: disable=broad-except
except Exception as err:
except Exception as err: # pylint: disable=broad-except
self._connected = False
_LOGGER.error("Exception while linking %s: %s",
self._address, str(err))

View File

@ -58,8 +58,7 @@ class DlibFaceDetectEntity(ImageProcessingFaceEntity):
def process_image(self, image):
"""Process image."""
# pylint: disable=import-error
import face_recognition
import face_recognition # pylint: disable=import-error
fak_file = io.BytesIO(image)
fak_file.name = 'snapshot.jpg'

View File

@ -20,8 +20,7 @@ TAP_KEY_SCHEMA = vol.Schema({})
def setup(hass, config):
"""Listen for keyboard events."""
# pylint: disable=import-error
import pykeyboard
import pykeyboard # pylint: disable=import-error
keyboard = pykeyboard.PyKeyboard()
keyboard.special_key_assignment()

View File

@ -4,7 +4,6 @@ Receive signals from a keyboard and use it as a remote control.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/keyboard_remote/
"""
# pylint: disable=import-error
import threading
import logging
import os
@ -90,6 +89,7 @@ class KeyboardRemoteThread(threading.Thread):
id_folder = '/dev/input/by-id/'
if os.path.isdir(id_folder):
# pylint: disable=import-error
from evdev import InputDevice, list_devices
device_names = [InputDevice(file_name).name
for file_name in list_devices()]
@ -104,6 +104,7 @@ class KeyboardRemoteThread(threading.Thread):
def _get_keyboard_device(self):
"""Get the keyboard device."""
# pylint: disable=import-error
from evdev import InputDevice, list_devices
if self.device_name:
devices = [InputDevice(file_name) for file_name in list_devices()]
@ -121,6 +122,7 @@ class KeyboardRemoteThread(threading.Thread):
def run(self):
"""Run the loop of the KeyboardRemote."""
# pylint: disable=import-error
from evdev import categorize, ecodes
if self.dev is not None:

View File

@ -38,8 +38,7 @@ class HomeKitLight(HomeKitEntity, Light):
def update_characteristics(self, characteristics):
"""Synchronise light state with Home Assistant."""
# pylint: disable=import-error
import homekit
import homekit # pylint: disable=import-error
for characteristic in characteristics:
ctype = characteristic['type']

View File

@ -447,16 +447,15 @@ class SonosDevice(MediaPlayerDevice):
"""Set available favorites."""
# SoCo 0.16 raises a generic Exception on invalid xml in favorites.
# Filter those out now so our list is safe to use.
# pylint: disable=broad-except
try:
self._favorites = []
for fav in self.soco.music_library.get_sonos_favorites():
try:
if fav.reference.get_uri():
self._favorites.append(fav)
except Exception:
except Exception: # pylint: disable=broad-except
_LOGGER.debug("Ignoring invalid favorite '%s'", fav.title)
except Exception:
except Exception: # pylint: disable=broad-except
_LOGGER.debug("Ignoring invalid favorite list")
def _radio_artwork(self, url):

View File

@ -4,7 +4,6 @@ Support for controlling raspihats boards.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/raspihats/
"""
# pylint: disable=import-error,no-name-in-module
import logging
import threading
import time
@ -125,7 +124,7 @@ class I2CHatsManager(threading.Thread):
with self._lock:
i2c_hat = self._i2c_hats.get(address)
if i2c_hat is None:
# pylint: disable=import-error
# pylint: disable=import-error,no-name-in-module
import raspihats.i2c_hats as module
constructor = getattr(module, board)
i2c_hat = constructor(address)
@ -143,6 +142,7 @@ class I2CHatsManager(threading.Thread):
def run(self):
"""Keep alive for I2C-HATs."""
# pylint: disable=import-error,no-name-in-module
from raspihats.i2c_hats import ResponseException
_LOGGER.info(log_message(self, "starting"))
@ -205,6 +205,7 @@ class I2CHatsManager(threading.Thread):
def read_di(self, address, channel):
"""Read a value from a I2C-HAT digital input."""
# pylint: disable=import-error,no-name-in-module
from raspihats.i2c_hats import ResponseException
with self._lock:
@ -217,6 +218,7 @@ class I2CHatsManager(threading.Thread):
def write_dq(self, address, channel, value):
"""Write a value to a I2C-HAT digital output."""
# pylint: disable=import-error,no-name-in-module
from raspihats.i2c_hats import ResponseException
with self._lock:
@ -228,6 +230,7 @@ class I2CHatsManager(threading.Thread):
def read_dq(self, address, channel):
"""Read a value from a I2C-HAT digital output."""
# pylint: disable=import-error,no-name-in-module
from raspihats.i2c_hats import ResponseException
with self._lock:

View File

@ -4,7 +4,6 @@ Support for controlling GPIO pins of a Raspberry Pi.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/rpi_gpio/
"""
# pylint: disable=import-error
import logging
from homeassistant.const import (
@ -19,7 +18,7 @@ DOMAIN = 'rpi_gpio'
def setup(hass, config):
"""Set up the Raspberry PI GPIO component."""
from RPi import GPIO
from RPi import GPIO # pylint: disable=import-error
def cleanup_gpio(event):
"""Stuff to do before stopping."""
@ -36,32 +35,32 @@ def setup(hass, config):
def setup_output(port):
"""Set up a GPIO as output."""
from RPi import GPIO
from RPi import GPIO # pylint: disable=import-error
GPIO.setup(port, GPIO.OUT)
def setup_input(port, pull_mode):
"""Set up a GPIO as input."""
from RPi import GPIO
from RPi import GPIO # pylint: disable=import-error
GPIO.setup(port, GPIO.IN,
GPIO.PUD_DOWN if pull_mode == 'DOWN' else GPIO.PUD_UP)
def write_output(port, value):
"""Write a value to a GPIO."""
from RPi import GPIO
from RPi import GPIO # pylint: disable=import-error
GPIO.output(port, value)
def read_input(port):
"""Read a value from a GPIO."""
from RPi import GPIO
from RPi import GPIO # pylint: disable=import-error
return GPIO.input(port)
def edge_detect(port, event_callback, bounce):
"""Add detection for RISING and FALLING events."""
from RPi import GPIO
from RPi import GPIO # pylint: disable=import-error
GPIO.add_event_detect(
port,
GPIO.BOTH,

View File

@ -42,11 +42,10 @@ def setup(hass, config):
device = config[DOMAIN][CONF_DEVICE]
global SCSGATE
# pylint: disable=broad-except
try:
SCSGATE = SCSGate(device=device, logger=_LOGGER)
SCSGATE.start()
except Exception as exception:
except Exception as exception: # pylint: disable=broad-except
_LOGGER.error("Cannot setup SCSGate component: %s", exception)
return False
@ -101,10 +100,9 @@ class SCSGate:
if new_device_activated:
self._activate_next_device()
# pylint: disable=broad-except
try:
self._devices[message.entity].process_event(message)
except Exception as exception:
except Exception as exception: # pylint: disable=broad-except
msg = "Exception while processing event: {}".format(exception)
self._logger.error(msg)
else:

View File

@ -64,12 +64,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
# pylint: disable=import-error
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the BH1750 sensor."""
import smbus
from i2csense.bh1750 import BH1750
import smbus # pylint: disable=import-error
from i2csense.bh1750 import BH1750 # pylint: disable=import-error
name = config.get(CONF_NAME)
bus_number = config.get(CONF_I2C_BUS)

View File

@ -79,12 +79,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
# pylint: disable=import-error
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the BME280 sensor."""
import smbus
from i2csense.bme280 import BME280
import smbus # pylint: disable=import-error
from i2csense.bme280 import BME280 # pylint: disable=import-error
SENSOR_TYPES[SENSOR_TEMP][1] = hass.config.units.temperature_unit
name = config.get(CONF_NAME)

View File

@ -115,15 +115,15 @@ async def async_setup_platform(hass, config, async_add_entities,
return
# pylint: disable=import-error, no-member
def _setup_bme680(config):
"""Set up and configure the BME680 sensor."""
from smbus import SMBus
from smbus import SMBus # pylint: disable=import-error
import bme680
sensor_handler = None
sensor = None
try:
# pylint: disable=no-member
i2c_address = config.get(CONF_I2C_ADDRESS)
bus = SMBus(config.get(CONF_I2C_BUS))
sensor = bme680.BME680(i2c_address, bus)

View File

@ -53,8 +53,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the DHT sensor."""
# pylint: disable=import-error
import Adafruit_DHT
import Adafruit_DHT # pylint: disable=import-error
SENSOR_TYPES[SENSOR_TEMPERATURE][1] = hass.config.units.temperature_unit
available_sensors = {

View File

@ -138,8 +138,7 @@ class Monitor:
additional_info['namespace'], additional_info['instance'],
packet.temperature)
# pylint: disable=import-error
from beacontools import (
from beacontools import ( # pylint: disable=import-error
BeaconScanner, EddystoneFilter, EddystoneTLMFrame)
device_filters = [EddystoneFilter(d.namespace, d.instance)
for d in devices]

View File

@ -63,7 +63,6 @@ FILTER_SCHEMA = vol.Schema({
default=DEFAULT_PRECISION): vol.Coerce(int),
})
# pylint: disable=redefined-builtin
FILTER_OUTLIER_SCHEMA = FILTER_SCHEMA.extend({
vol.Required(CONF_FILTER_NAME): FILTER_NAME_OUTLIER,
vol.Optional(CONF_FILTER_WINDOW_SIZE,
@ -446,7 +445,8 @@ class TimeSMAFilter(Filter):
variant (enum): type of argorithm used to connect discrete values
"""
def __init__(self, window_size, precision, entity, type):
def __init__(self, window_size, precision, entity,
type): # pylint: disable=redefined-builtin
"""Initialize Filter."""
super().__init__(FILTER_NAME_TIME_SMA, window_size, precision, entity)
self._time_window = window_size

View File

@ -239,8 +239,7 @@ class FritzBoxPhonebook:
self.number_dict = None
self.prefixes = prefixes or []
# pylint: disable=import-error
import fritzconnection as fc
import fritzconnection as fc # pylint: disable=import-error
# Establish a connection to the FRITZ!Box.
self.fph = fc.FritzPhonebook(
address=self.host, user=self.username, password=self.password)

View File

@ -38,12 +38,11 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
})
# pylint: disable=import-error
async def async_setup_platform(hass, config, async_add_entities,
discovery_info=None):
"""Set up the HTU21D sensor."""
import smbus
from i2csense.htu21d import HTU21D
import smbus # pylint: disable=import-error
from i2csense.htu21d import HTU21D # pylint: disable=import-error
name = config.get(CONF_NAME)
bus_number = config.get(CONF_I2C_BUS)

View File

@ -32,8 +32,7 @@ class HomeKitSwitch(HomeKitEntity, SwitchDevice):
def update_characteristics(self, characteristics):
"""Synchronise the switch state with Home Assistant."""
# pylint: disable=import-error
import homekit
import homekit # pylint: disable=import-error
for characteristic in characteristics:
ctype = characteristic['type']

View File

@ -87,7 +87,6 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
def get_engine(hass, config):
"""Set up Amazon Polly speech component."""
# pylint: disable=import-error
output_format = config.get(CONF_OUTPUT_FORMAT)
sample_rate = config.get(CONF_SAMPLE_RATE,
DEFAULT_SAMPLE_RATES[output_format])

View File

@ -4,9 +4,9 @@ Support to check for available updates.
For more details about this component, please refer to the documentation at
https://home-assistant.io/components/updater/
"""
# pylint: disable=no-name-in-module, import-error
import asyncio
from datetime import timedelta
# pylint: disable=import-error,no-name-in-module
from distutils.version import StrictVersion
import json
import logging

View File

@ -25,7 +25,7 @@ from typing import Any
def patch_weakref_tasks() -> None:
"""Replace weakref.WeakSet to address Python 3 bug."""
# pylint: disable=no-self-use, protected-access, bare-except
# pylint: disable=no-self-use, protected-access
import asyncio.tasks
class IgnoreCalls:
@ -38,7 +38,7 @@ def patch_weakref_tasks() -> None:
asyncio.tasks.Task._all_tasks = IgnoreCalls() # type: ignore
try:
del asyncio.tasks.Task.__del__
except: # noqa: E722
except: # noqa: E722 pylint: disable=bare-except
pass

View File

@ -145,8 +145,7 @@ def run_coroutine_threadsafe(
"""Handle the call to the coroutine."""
try:
_chain_future(ensure_future(coro, loop=loop), future)
# pylint: disable=broad-except
except Exception as exc:
except Exception as exc: # pylint: disable=broad-except
if future.set_running_or_notify_cancel():
future.set_exception(exc)
else:
@ -194,8 +193,7 @@ def run_callback_threadsafe(loop: AbstractEventLoop, callback: Callable,
"""Run callback and store result."""
try:
future.set_result(callback(*args))
# pylint: disable=broad-except
except Exception as exc:
except Exception as exc: # pylint: disable=broad-except
if future.set_running_or_notify_cancel():
future.set_exception(exc)
else: