From 94249645624d83151306dfd1f23796f224d57615 Mon Sep 17 00:00:00 2001 From: Teemu Rytilahti Date: Wed, 6 Sep 2017 20:14:19 +0300 Subject: [PATCH] make flake8 happy, fix some issues reported by landscape --- mirobo/device.py | 41 +++++++++++++++++++++-------------------- mirobo/discovery.py | 14 ++++++++------ mirobo/plug_cli.py | 2 +- mirobo/protocol.py | 2 +- mirobo/vacuum.py | 12 ++++++------ mirobo/vacuum_cli.py | 16 +++++++--------- 6 files changed, 44 insertions(+), 43 deletions(-) diff --git a/mirobo/device.py b/mirobo/device.py index 8eac3fd1d..0eee0a520 100644 --- a/mirobo/device.py +++ b/mirobo/device.py @@ -2,7 +2,7 @@ import datetime import socket import logging -from typing import Any, List +from typing import Any, List # noqa: F401 from .protocol import Message @@ -63,11 +63,11 @@ def do_discover(self): self._device_ts = m.header.value.ts if self.debug > 1: _LOGGER.debug(m) - _LOGGER.debug("Discovered %s %s with ts: %s, token: %s" % ( - self._devtype, - self._serial, - self._device_ts, - codecs.encode(m.checksum, 'hex'))) + _LOGGER.debug("Discovered %s %s with ts: %s, token: %s", + self._devtype, + self._serial, + self._device_ts, + codecs.encode(m.checksum, 'hex')) else: _LOGGER.error("Unable to discover a device at address %s", self.ip) raise DeviceException("Unable to discover the device %s" % self.ip) @@ -98,15 +98,15 @@ def discover(addr: str=None) -> Any: try: data, addr = s.recvfrom(1024) m = Message.parse(data) # type: Message - _LOGGER.debug("Got a response: %s" % m) + _LOGGER.debug("Got a response: %s", m) if not is_broadcast: return m if addr[0] not in seen_addrs: - _LOGGER.info(" IP %s: %s - token: %s" % ( - addr[0], - m.header.value.devtype, - codecs.encode(m.checksum, 'hex'))) + _LOGGER.info(" IP %s: %s - token: %s", + addr[0], + m.header.value.devtype, + codecs.encode(m.checksum, 'hex')) seen_addrs.append(addr[0]) except socket.timeout: if is_broadcast: @@ -138,7 +138,7 @@ def send(self, command: str, parameters: Any=None, retry_count=3) -> Any: 'checksum': 0} ctx = {'token': self.token} m = Message.build(msg, ctx) - _LOGGER.debug("%s:%s >>: %s" % (self.ip, self.port, cmd)) + _LOGGER.debug("%s:%s >>: %s", self.ip, self.port, cmd) if self.debug > 1: _LOGGER.debug("send (timeout %s): %s", self._timeout, Message.parse(m, ctx)) @@ -149,7 +149,7 @@ def send(self, command: str, parameters: Any=None, retry_count=3) -> Any: try: s.sendto(m, (self.ip, self.port)) except OSError as ex: - _LOGGER.error("failed to send msg: %s" % ex) + _LOGGER.error("failed to send msg: %s", ex) raise DeviceException from ex try: @@ -157,13 +157,14 @@ def send(self, command: str, parameters: Any=None, retry_count=3) -> Any: m = Message.parse(data, ctx) self._device_ts = m.header.value.ts if self.debug > 1: - _LOGGER.debug("recv: %s" % m) + _LOGGER.debug("recv: %s", m) self.__id = m.data.value["id"] - _LOGGER.debug("%s:%s (ts: %s, id: %s) << %s" % (self.ip, self.port, - m.header.value.ts, - m.data.value["id"], - m.data.value)) + _LOGGER.debug("%s:%s (ts: %s, id: %s) << %s", + self.ip, self.port, + m.header.value.ts, + m.data.value["id"], + m.data.value) try: return m.data.value["result"] except KeyError: @@ -172,9 +173,9 @@ def send(self, command: str, parameters: Any=None, retry_count=3) -> Any: _LOGGER.error("Got error when receiving: %s", ex) if retry_count > 0: _LOGGER.warning("Retrying with incremented id, " - "retries left: %s" % retry_count) + "retries left: %s", retry_count) self.__id += 100 - return self.send(command, parameters, retry_count-1) + return self.send(command, parameters, retry_count - 1) raise DeviceException from ex def raw_command(self, cmd, params): diff --git a/mirobo/discovery.py b/mirobo/discovery.py index d6e848ce7..bea5320f9 100644 --- a/mirobo/discovery.py +++ b/mirobo/discovery.py @@ -5,7 +5,7 @@ import codecs from mirobo import (Device, Vacuum, Plug, PlugV1, Strip, AirPurifier, Ceil, PhilipsEyecare, ChuangmiIr) -from typing import Union, Callable, Dict +from typing import Union, Callable, Dict # noqa: F401 _LOGGER = logging.getLogger(__name__) @@ -31,18 +31,20 @@ def _check_if_supported(self, info, addr): m = dev.do_discover() dev.token = m.checksum _LOGGER.info( - "Found supported '%s' at %s:%s (%s) token: %s" % - (v.__name__, addr, info.port, name, - codecs.encode(dev.token, 'hex'))) + "Found supported '%s' at %s:%s (%s) token: %s", + v.__name__, + addr, info.port, + name, + codecs.encode(dev.token, 'hex')) return dev elif callable(v): _LOGGER.info(v(info)) dev = Device(ip=addr) - _LOGGER.info("token: %s" % codecs.encode( + _LOGGER.info("token: %s", codecs.encode( dev.do_discover().checksum, 'hex')) return None _LOGGER.warning("Found unsupported device %s at %s, " - "please report to developers" % (name, addr)) + "please report to developers", name, addr) return None def add_service(self, zeroconf, type, name): diff --git a/mirobo/plug_cli.py b/mirobo/plug_cli.py index 4f274acec..f99e7928b 100644 --- a/mirobo/plug_cli.py +++ b/mirobo/plug_cli.py @@ -4,7 +4,7 @@ import ast import sys import ipaddress -from typing import Any +from typing import Any # noqa: F401 if sys.version_info < (3, 4): print("To use this script you need python 3.4 or newer, got %s" % diff --git a/mirobo/protocol.py b/mirobo/protocol.py index 6df58f8b6..b8bfe5748 100644 --- a/mirobo/protocol.py +++ b/mirobo/protocol.py @@ -135,7 +135,7 @@ def _decode(self, obj, context): # pp(context) decrypted = Utils.decrypt(obj, context['_']['token']) decrypted = decrypted.rstrip(b"\x00") - except Exception as ex: + except Exception: _LOGGER.debug("Unable to decrypt, returning raw bytes.") return obj diff --git a/mirobo/vacuum.py b/mirobo/vacuum.py index eb9327882..862dd7aa8 100644 --- a/mirobo/vacuum.py +++ b/mirobo/vacuum.py @@ -93,7 +93,7 @@ def status(self) -> VacuumStatus: def enable_log_upload(self): raise NotImplementedError("unknown parameters") - return self.send("enable_log_upload") + # return self.send("enable_log_upload") def log_upload_status(self): # {"result": [{"log_upload_status": 7}], "id": 1} @@ -105,8 +105,8 @@ def consumable_status(self) -> ConsumableStatus: def consumable_reset(self): """Reset consumable information.""" - raise NotImplementedError() - self.send("reset_consumable", ["unknown"]) + raise NotImplementedError("unknown parameters") + # self.send("reset_consumable", ["unknown"]) def map(self): """Return map token.""" @@ -143,9 +143,9 @@ def set_timer(self, details): # how to create timers/change values? # ['ts', 'on'] to enable raise NotImplementedError() - return self.send( - "set_timer", [["ts", ["cron_line", ["start_clean", ""]]]]) - return self.send("upd_timer", ["ts", "on"]) + # return self.send( + # "set_timer", [["ts", ["cron_line", ["start_clean", ""]]]]) + # return self.send("upd_timer", ["ts", "on"]) def dnd_status(self): """Returns do-not-disturb status.""" diff --git a/mirobo/vacuum_cli.py b/mirobo/vacuum_cli.py index 192c193a2..10893e782 100644 --- a/mirobo/vacuum_cli.py +++ b/mirobo/vacuum_cli.py @@ -7,7 +7,7 @@ import json import ipaddress from pprint import pformat as pf -from typing import Any +from typing import Any # noqa: F401 if sys.version_info < (3, 4): @@ -71,10 +71,9 @@ def cli(ctx, ip: str, token: str, debug: int, id_file: str): x = json.load(f) start_id = x.get("seq", 0) manual_seq = x.get("manual_seq", 0) - _LOGGER.debug("Read stored sequence ids: %s" % x) + _LOGGER.debug("Read stored sequence ids: %s", x) except (FileNotFoundError, TypeError) as ex: - _LOGGER.error("Unable to read the stored msgid: %s" % ex) - pass + _LOGGER.error("Unable to read the stored msgid: %s", ex) vac = mirobo.Vacuum(ip, token, start_id, debug) @@ -95,7 +94,7 @@ def cleanup(vac: mirobo.Vacuum, **kwargs): return id_file = kwargs['id_file'] seqs = {'seq': vac.raw_id, 'manual_seq': vac.manual_seqnum} - _LOGGER.debug("Writing %s to %s" % (seqs, id_file)) + _LOGGER.debug("Writing %s to %s", seqs, id_file) with open(id_file, 'w') as f: json.dump(seqs, f) @@ -195,7 +194,7 @@ def manual(vac: mirobo.Vacuum): # if not vac.manual_mode and command : -@manual.command() +@manual.command() # noqa: F811 # redefinition of start @pass_dev def start(vac: mirobo.Vacuum): """Activate the manual mode.""" @@ -203,7 +202,7 @@ def start(vac: mirobo.Vacuum): return vac.manual_start() -@manual.command() +@manual.command() # noqa: F811 # redefinition of stop @pass_dev def stop(vac: mirobo.Vacuum): """Deactivate the manual mode.""" @@ -303,7 +302,6 @@ def timer(vac: mirobo.Vacuum, timer): if timer: raise NotImplementedError() # vac.set_timer(x) - pass else: timers = vac.timer() for idx, timer in enumerate(timers): @@ -341,7 +339,7 @@ def info(vac: mirobo.Vacuum): res = vac.info() click.echo(res) - _LOGGER.debug("Full response: %s" % pf(res.raw)) + _LOGGER.debug("Full response: %s", pf(res.raw)) @cli.command()