Skip to content

Commit

Permalink
lint flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Mips2648 committed Dec 1, 2024
1 parent 85046ad commit 06e819d
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 140
3 changes: 2 additions & 1 deletion jeedomdaemon/aio_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions jeedomdaemon/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions jeedomdaemon/base_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .aio_connector import Publisher, Listener
from .base_config import BaseConfig


class BaseDaemon:
"""Base daemon class for your daemon
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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

Expand All @@ -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()]
Expand All @@ -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):
Expand All @@ -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):
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# pylint: disable=missing-module-docstring
from setuptools import setup, find_packages

__version__ = "1.1.0"
Expand Down
3 changes: 2 additions & 1 deletion tests/base_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions tests/base_daemon_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down

0 comments on commit 06e819d

Please sign in to comment.