diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..2b21f65 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 140 \ No newline at end of file diff --git a/jeedomdaemon/aio_connector.py b/jeedomdaemon/aio_connector.py index 15306c6..dc1fd8c 100644 --- a/jeedomdaemon/aio_connector.py +++ b/jeedomdaemon/aio_connector.py @@ -50,6 +50,7 @@ async def __handle_read(self, reader: asyncio.StreamReader, writer: asyncio.Stre await writer.wait_closed() await self._on_message_cb(json.loads(message)) + class Publisher(): """This class allows to push information to Jeedom either immediately by calling function `send_to_jeedom` or in cycle by calling function `add_change`. For the "cycle" mode, a task must be created by calling `create_send_task` and awaited""" def __init__(self, callback_url: str, api_key: str, cycle: float = 0.5) -> None: @@ -155,7 +156,7 @@ async def add_change(self, key: str, value): async def __merge_dict(self, dic1: dict, dic2: dict): for key, val2 in dic2.items(): - val1 = dic1.get(key) # returns None if v1 has no value for this key + val1 = dic1.get(key) # returns None if v1 has no value for this key if isinstance(val1, Mapping) and isinstance(val2, Mapping): await self.__merge_dict(val1, val2) else: diff --git a/jeedomdaemon/base_config.py b/jeedomdaemon/base_config.py index 6df2f47..b15ba7a 100644 --- a/jeedomdaemon/base_config.py +++ b/jeedomdaemon/base_config.py @@ -5,6 +5,7 @@ import argparse from typing import Sequence + class BaseConfig(): """Base config class, if you need a custom configuration you can inherit from this class diff --git a/jeedomdaemon/base_daemon.py b/jeedomdaemon/base_daemon.py index 76b4824..e25bdbb 100644 --- a/jeedomdaemon/base_daemon.py +++ b/jeedomdaemon/base_daemon.py @@ -14,6 +14,7 @@ from .aio_connector import Publisher, Listener from .base_config import BaseConfig + class BaseDaemon: """Base daemon class for your daemon @@ -85,7 +86,7 @@ def run(self): Utils.write_pid(str(self._config.pid_filename)) asyncio.run(self.__run()) - except Exception as ex: # pylint: disable=broad-exception-caught + except Exception as ex: exception_type, exception_object, exception_traceback = sys.exc_info() filename = exception_traceback.tb_frame.f_code.co_filename line_number = exception_traceback.tb_lineno @@ -95,7 +96,7 @@ def run(self): try: self._logger.debug("Removing PID file %s", self._config.pid_filename) os.remove(self._config.pid_filename) - except: # pylint: disable=bare-except + except: # noqa: E722 pass self._logger.debug("Exit 0") @@ -116,14 +117,14 @@ async def __run(self): if self.__on_start_cb is not None and asyncio.iscoroutinefunction(self.__on_start_cb): try: await self.__on_start_cb() - except BaseException as e: # pylint: disable=broad-exception-caught + except BaseException as e: self._logger.warning("Exception occurred when calling on_start_cb: %s", e) return self._publisher.create_send_task() await self.__add_signal_handler() - await asyncio.sleep(1) # allow all tasks to start + await asyncio.sleep(1) # allow all tasks to start await self.__listen_task @@ -133,7 +134,7 @@ async def stop(self): if self.__on_stop_cb is not None: try: await self.__on_stop_cb() - except BaseException as e: # pylint: disable=broad-exception-caught + except BaseException as e: self._logger.warning("Exception occurred when calling on_stop_cb: %s", e) tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()] @@ -142,7 +143,7 @@ async def stop(self): task.cancel() try: asyncio.gather(*tasks, return_exceptions=True) - except BaseException as e: # pylint: disable=broad-exception-caught + except BaseException as e: self._logger.warning("Some exception occurred during cancellation: %s", e) def __ask_exit(self, sig): @@ -163,7 +164,7 @@ async def __on_socket_message(self, message): else: self._logger.warning('Message received on socket but no callback defined') - except Exception as e: # pylint: disable=broad-exception-caught + except Exception as e: self._logger.error('Send command to daemon error: %s', e) async def send_to_jeedom(self, payload): diff --git a/setup.py b/setup.py index da42239..d108e68 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -# pylint: disable=missing-module-docstring from setuptools import setup, find_packages __version__ = "1.1.0" diff --git a/tests/base_config_test.py b/tests/base_config_test.py index f79c101..be8a4d3 100644 --- a/tests/base_config_test.py +++ b/tests/base_config_test.py @@ -6,7 +6,8 @@ sys.path.append(os.path.realpath(os.path.dirname(__file__) + '/..')) -from jeedomdaemon.base_config import BaseConfig # pylint: disable=wrong-import-position +from jeedomdaemon.base_config import BaseConfig # noqa: E402 + class TestBaseConfig(unittest.TestCase): def test_base_config_creation(self): diff --git a/tests/base_daemon_test.py b/tests/base_daemon_test.py index df4541d..5b2deb3 100644 --- a/tests/base_daemon_test.py +++ b/tests/base_daemon_test.py @@ -8,8 +8,9 @@ sys.path.append(os.path.realpath(os.path.dirname(__file__) + '/..')) -from jeedomdaemon.base_daemon import BaseDaemon # pylint: disable=wrong-import-position -from jeedomdaemon.base_config import BaseConfig # pylint: disable=wrong-import-position +from jeedomdaemon.base_daemon import BaseDaemon # noqa: E402 +from jeedomdaemon.base_config import BaseConfig # noqa: E402 + class TestBaseDaemon():