mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 23:14:54 +01:00
Bump pylint from 2.5.3 to 2.6.0 (#1262)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
parent
a401c71d3e
commit
e7bd93b4b0
17 changed files with 53 additions and 37 deletions
|
@ -181,7 +181,7 @@ class APIClient(threading.Thread):
|
|||
self._address)
|
||||
_LOGGER.warning("(If this error persists, please set a static IP address: "
|
||||
"https://esphome.io/components/wifi.html#manual-ips)")
|
||||
raise APIConnectionError(err)
|
||||
raise APIConnectionError(err) from err
|
||||
|
||||
_LOGGER.info("Connecting to %s:%s (%s)", self._address, self._port, ip)
|
||||
self._socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
@ -346,12 +346,12 @@ class APIClient(threading.Thread):
|
|||
raise APIConnectionError("No socket!")
|
||||
try:
|
||||
val = self._socket.recv(amount - len(ret))
|
||||
except AttributeError:
|
||||
raise APIConnectionError("Socket was closed")
|
||||
except AttributeError as err:
|
||||
raise APIConnectionError("Socket was closed") from err
|
||||
except socket.timeout:
|
||||
continue
|
||||
except OSError as err:
|
||||
raise APIConnectionError(f"Error while receiving data: {err}")
|
||||
raise APIConnectionError(f"Error while receiving data: {err}") from err
|
||||
ret += val
|
||||
return ret
|
||||
|
||||
|
|
|
@ -84,6 +84,7 @@ def validate_automation(extra_schema=None, extra_validators=None, single=False):
|
|||
return cv.Schema([schema])(value)
|
||||
except cv.Invalid as err2:
|
||||
if 'extra keys not allowed' in str(err2) and len(err2.path) == 2:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise err
|
||||
if 'Unable to find action' in str(err):
|
||||
raise err2
|
||||
|
|
|
@ -104,6 +104,7 @@ def parse_multi_click_timing_str(value):
|
|||
try:
|
||||
state = cv.boolean(parts[0])
|
||||
except cv.Invalid:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise cv.Invalid("First word must either be ON or OFF, not {}".format(parts[0]))
|
||||
|
||||
if parts[1] != 'for':
|
||||
|
|
|
@ -42,9 +42,9 @@ def validate_glyphs(value):
|
|||
def validate_pillow_installed(value):
|
||||
try:
|
||||
import PIL
|
||||
except ImportError:
|
||||
except ImportError as err:
|
||||
raise cv.Invalid("Please install the pillow python package to use this feature. "
|
||||
"(pip install pillow)")
|
||||
"(pip install pillow)") from err
|
||||
|
||||
if PIL.__version__[0] < '4':
|
||||
raise cv.Invalid("Please update your pillow installation to at least 4.0.x. "
|
||||
|
|
|
@ -43,8 +43,8 @@ def validate_url(value):
|
|||
value = cv.string(value)
|
||||
try:
|
||||
parsed = list(urlparse.urlparse(value))
|
||||
except Exception:
|
||||
raise cv.Invalid('Invalid URL')
|
||||
except Exception as err:
|
||||
raise cv.Invalid('Invalid URL') from err
|
||||
|
||||
if not parsed[0] or not parsed[1]:
|
||||
raise cv.Invalid('URL must have a URL scheme and host')
|
||||
|
|
|
@ -18,8 +18,8 @@ def validate_uid(value):
|
|||
"long.")
|
||||
try:
|
||||
x = int(x, 16)
|
||||
except ValueError:
|
||||
raise cv.Invalid("Valid characters for parts of a UID are 0123456789ABCDEF.")
|
||||
except ValueError as err:
|
||||
raise cv.Invalid("Valid characters for parts of a UID are 0123456789ABCDEF.") from err
|
||||
if x < 0 or x > 255:
|
||||
raise cv.Invalid("Valid values for UID parts (separated by '-') are 00 to FF")
|
||||
return value
|
||||
|
|
|
@ -28,6 +28,7 @@ def validate_acceleration(value):
|
|||
try:
|
||||
value = float(value)
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise cv.Invalid(f"Expected acceleration as floating point number, got {value}")
|
||||
|
||||
if value <= 0:
|
||||
|
@ -48,6 +49,7 @@ def validate_speed(value):
|
|||
try:
|
||||
value = float(value)
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise cv.Invalid(f"Expected speed as floating point number, got {value}")
|
||||
|
||||
if value <= 0:
|
||||
|
|
|
@ -138,6 +138,7 @@ def _parse_cron_int(value, special_mapping, message):
|
|||
try:
|
||||
return int(value)
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise cv.Invalid(message.format(value))
|
||||
|
||||
|
||||
|
@ -158,6 +159,7 @@ def _parse_cron_part(part, min_value, max_value, special_mapping):
|
|||
try:
|
||||
repeat_n = int(repeat)
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise cv.Invalid("Repeat for '/' time expression must be an integer, got {}"
|
||||
.format(repeat))
|
||||
return set(range(offset_n, max_value + 1, repeat_n))
|
||||
|
|
|
@ -18,9 +18,9 @@ _LOGGER = logging.getLogger(__name__)
|
|||
def validate_cryptography_installed():
|
||||
try:
|
||||
import cryptography
|
||||
except ImportError:
|
||||
except ImportError as err:
|
||||
raise cv.Invalid("This settings requires the cryptography python package. "
|
||||
"Please install it with `pip install cryptography`")
|
||||
"Please install it with `pip install cryptography`") from err
|
||||
|
||||
if cryptography.__version__[0] < '2':
|
||||
raise cv.Invalid("Please update your python cryptography installation to least 2.x "
|
||||
|
|
|
@ -675,7 +675,7 @@ def _load_config(command_line_substitutions):
|
|||
try:
|
||||
config = yaml_util.load_yaml(CORE.config_path)
|
||||
except EsphomeError as e:
|
||||
raise InvalidYAMLError(e)
|
||||
raise InvalidYAMLError(e) from e
|
||||
CORE.raw_config = config
|
||||
|
||||
try:
|
||||
|
@ -693,7 +693,7 @@ def load_config(command_line_substitutions):
|
|||
try:
|
||||
return _load_config(command_line_substitutions)
|
||||
except vol.Invalid as err:
|
||||
raise EsphomeError(f"Error while parsing config: {err}")
|
||||
raise EsphomeError(f"Error while parsing config: {err}") from err
|
||||
|
||||
|
||||
def line_info(obj, highlight=True):
|
||||
|
|
|
@ -224,6 +224,7 @@ def int_(value):
|
|||
try:
|
||||
return int(value, base)
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid(f"Expected integer, but cannot parse {value} as an integer")
|
||||
|
||||
|
||||
|
@ -423,6 +424,7 @@ def time_period_str_colon(value):
|
|||
try:
|
||||
parsed = [int(x) for x in value.split(':')]
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid(TIME_PERIOD_ERROR.format(value))
|
||||
|
||||
if len(parsed) == 2:
|
||||
|
@ -527,6 +529,7 @@ def time_of_day(value):
|
|||
try:
|
||||
date = datetime.strptime(value, '%H:%M:%S %p')
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid(f"Invalid time of day: {err}")
|
||||
|
||||
return {
|
||||
|
@ -548,6 +551,7 @@ def mac_address(value):
|
|||
try:
|
||||
parts_int.append(int(part, 16))
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid("MAC Address parts must be hexadecimal values from 00 to FF")
|
||||
|
||||
return core.MACAddress(*parts_int)
|
||||
|
@ -565,6 +569,7 @@ def bind_key(value):
|
|||
try:
|
||||
parts_int.append(int(part, 16))
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid("Bind key must be hex values from 00 to FF")
|
||||
|
||||
return ''.join(f'{part:02X}' for part in parts_int)
|
||||
|
@ -686,8 +691,8 @@ def domain(value):
|
|||
return value
|
||||
try:
|
||||
return str(ipv4(value))
|
||||
except Invalid:
|
||||
raise Invalid(f"Invalid domain: {value}")
|
||||
except Invalid as err:
|
||||
raise Invalid(f"Invalid domain: {value}") from err
|
||||
|
||||
|
||||
def domain_name(value):
|
||||
|
@ -739,8 +744,8 @@ def _valid_topic(value):
|
|||
value = string(value)
|
||||
try:
|
||||
raw_value = value.encode('utf-8')
|
||||
except UnicodeError:
|
||||
raise Invalid("MQTT topic name/filter must be valid UTF-8 string.")
|
||||
except UnicodeError as err:
|
||||
raise Invalid("MQTT topic name/filter must be valid UTF-8 string.") from err
|
||||
if not raw_value:
|
||||
raise Invalid("MQTT topic name/filter must not be empty.")
|
||||
if len(raw_value) > 65535:
|
||||
|
@ -792,6 +797,7 @@ def mqtt_qos(value):
|
|||
try:
|
||||
value = int(value)
|
||||
except (TypeError, ValueError):
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid(f"MQTT Quality of Service must be integer, got {value}")
|
||||
return one_of(0, 1, 2)(value)
|
||||
|
||||
|
@ -836,6 +842,7 @@ def possibly_negative_percentage(value):
|
|||
else:
|
||||
value = float(value)
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid("invalid number")
|
||||
if value > 1:
|
||||
msg = "Percentage must not be higher than 100%."
|
||||
|
@ -1006,6 +1013,7 @@ def dimensions(value):
|
|||
try:
|
||||
width, height = int(value[0]), int(value[1])
|
||||
except ValueError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise Invalid("Width and height dimensions must be integers")
|
||||
if width <= 0 or height <= 0:
|
||||
raise Invalid("Width and height must at least be 1")
|
||||
|
|
|
@ -83,19 +83,19 @@ def receive_exactly(sock, amount, msg, expect, decode=True):
|
|||
try:
|
||||
data += recv_decode(sock, 1, decode=decode)
|
||||
except OSError as err:
|
||||
raise OTAError(f"Error receiving acknowledge {msg}: {err}")
|
||||
raise OTAError(f"Error receiving acknowledge {msg}: {err}") from err
|
||||
|
||||
try:
|
||||
check_error(data, expect)
|
||||
except OTAError as err:
|
||||
sock.close()
|
||||
raise OTAError(f"Error {msg}: {err}")
|
||||
raise OTAError(f"Error {msg}: {err}") from err
|
||||
|
||||
while len(data) < amount:
|
||||
try:
|
||||
data += recv_decode(sock, amount - len(data), decode=decode)
|
||||
except OSError as err:
|
||||
raise OTAError(f"Error receiving {msg}: {err}")
|
||||
raise OTAError(f"Error receiving {msg}: {err}") from err
|
||||
return data
|
||||
|
||||
|
||||
|
@ -151,7 +151,7 @@ def send_check(sock, data, msg):
|
|||
|
||||
sock.sendall(data)
|
||||
except OSError as err:
|
||||
raise OTAError(f"Error sending {msg}: {err}")
|
||||
raise OTAError(f"Error sending {msg}: {err}") from err
|
||||
|
||||
|
||||
def perform_ota(sock, password, file_handle, filename):
|
||||
|
@ -226,7 +226,7 @@ def perform_ota(sock, password, file_handle, filename):
|
|||
sock.sendall(chunk)
|
||||
except OSError as err:
|
||||
sys.stderr.write('\n')
|
||||
raise OTAError(f"Error sending data: {err}")
|
||||
raise OTAError(f"Error sending data: {err}") from err
|
||||
|
||||
progress.update(offset / float(file_size))
|
||||
progress.done()
|
||||
|
@ -259,7 +259,7 @@ def run_ota_impl_(remote_host, remote_port, password, filename):
|
|||
remote_host)
|
||||
_LOGGER.error("(If this error persists, please set a static IP address: "
|
||||
"https://esphome.io/components/wifi.html#manual-ips)")
|
||||
raise OTAError(err)
|
||||
raise OTAError(err) from err
|
||||
_LOGGER.info(" -> %s", ip)
|
||||
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
|
|
@ -89,7 +89,7 @@ def mkdir_p(path):
|
|||
pass
|
||||
else:
|
||||
from esphome.core import EsphomeError
|
||||
raise EsphomeError(f"Error creating directories {path}: {err}")
|
||||
raise EsphomeError(f"Error creating directories {path}: {err}") from err
|
||||
|
||||
|
||||
def is_ip_address(host):
|
||||
|
@ -110,13 +110,13 @@ def _resolve_with_zeroconf(host):
|
|||
|
||||
try:
|
||||
zc = Zeroconf()
|
||||
except Exception:
|
||||
except Exception as err:
|
||||
raise EsphomeError("Cannot start mDNS sockets, is this a docker container without "
|
||||
"host network mode?")
|
||||
"host network mode?") from err
|
||||
try:
|
||||
info = zc.resolve_host(host + '.')
|
||||
except Exception as err:
|
||||
raise EsphomeError(f"Error resolving mDNS hostname: {err}")
|
||||
raise EsphomeError(f"Error resolving mDNS hostname: {err}") from err
|
||||
finally:
|
||||
zc.close()
|
||||
if info is None:
|
||||
|
@ -142,7 +142,7 @@ def resolve_ip_address(host):
|
|||
except OSError as err:
|
||||
errs.append(str(err))
|
||||
raise EsphomeError("Error resolving IP address: {}"
|
||||
"".format(', '.join(errs)))
|
||||
"".format(', '.join(errs))) from err
|
||||
|
||||
|
||||
def get_bool_env(var, default=False):
|
||||
|
@ -165,10 +165,10 @@ def read_file(path):
|
|||
return f_handle.read()
|
||||
except OSError as err:
|
||||
from esphome.core import EsphomeError
|
||||
raise EsphomeError(f"Error reading file {path}: {err}")
|
||||
raise EsphomeError(f"Error reading file {path}: {err}") from err
|
||||
except UnicodeDecodeError as err:
|
||||
from esphome.core import EsphomeError
|
||||
raise EsphomeError(f"Error reading file {path}: {err}")
|
||||
raise EsphomeError(f"Error reading file {path}: {err}") from err
|
||||
|
||||
|
||||
def _write_file(path: Union[Path, str], text: Union[str, bytes]):
|
||||
|
@ -205,9 +205,9 @@ def _write_file(path: Union[Path, str], text: Union[str, bytes]):
|
|||
def write_file(path: Union[Path, str], text: str):
|
||||
try:
|
||||
_write_file(path, text)
|
||||
except OSError:
|
||||
except OSError as err:
|
||||
from esphome.core import EsphomeError
|
||||
raise EsphomeError(f"Could not write file at {path}")
|
||||
raise EsphomeError(f"Could not write file at {path}") from err
|
||||
|
||||
|
||||
def write_file_if_changed(path: Union[Path, str], text: str):
|
||||
|
@ -230,7 +230,7 @@ def copy_file_if_changed(src, dst):
|
|||
shutil.copy(src, dst)
|
||||
except OSError as err:
|
||||
from esphome.core import EsphomeError
|
||||
raise EsphomeError(f"Error copying file {src} to {dst}: {err}")
|
||||
raise EsphomeError(f"Error copying file {src} to {dst}: {err}") from err
|
||||
|
||||
|
||||
def list_starts_with(list_, sub):
|
||||
|
|
|
@ -67,7 +67,7 @@ def initialize(config, subscriptions, on_message, username, password, client_id)
|
|||
port = int(config[CONF_MQTT][CONF_PORT])
|
||||
client.connect(host, port)
|
||||
except OSError as err:
|
||||
raise EsphomeError(f"Cannot connect to MQTT broker: {err}")
|
||||
raise EsphomeError(f"Cannot connect to MQTT broker: {err}") from err
|
||||
|
||||
try:
|
||||
client.loop_forever()
|
||||
|
|
|
@ -32,6 +32,7 @@ class _Schema(vol.Schema):
|
|||
try:
|
||||
res = extra(res)
|
||||
except vol.Invalid as err:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise ensure_multiple_invalid(err)
|
||||
return res
|
||||
|
||||
|
|
|
@ -126,6 +126,7 @@ class ESPHomeLoader(yaml.SafeLoader): # pylint: disable=too-many-ancestors
|
|||
try:
|
||||
hash(key)
|
||||
except TypeError:
|
||||
# pylint: disable=raise-missing-from
|
||||
raise yaml.constructor.ConstructorError(
|
||||
f'Invalid key "{key}" (not hashable)', key_node.start_mark)
|
||||
|
||||
|
@ -297,7 +298,7 @@ def _load_yaml_internal(fname):
|
|||
try:
|
||||
return loader.get_single_data() or OrderedDict()
|
||||
except yaml.YAMLError as exc:
|
||||
raise EsphomeError(exc)
|
||||
raise EsphomeError(exc) from exc
|
||||
finally:
|
||||
loader.dispose()
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pylint==2.5.3
|
||||
pylint==2.6.0
|
||||
flake8==3.8.3
|
||||
pillow>4.0.0
|
||||
cryptography>=2.0.0,<4
|
||||
|
|
Loading…
Reference in a new issue