Skip to content

Commit

Permalink
pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
Mips2648 committed Apr 25, 2024
1 parent 4116eab commit 2493b67
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[FORMAT]
max-line-length=240
max-line-length=255
9 changes: 6 additions & 3 deletions jeedomdaemon/aio_connector.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Module providing Listener & Publisher class for your daemon."""

import logging
import json
import asyncio
Expand Down Expand Up @@ -78,7 +80,7 @@ async def test_callback(self):
if resp.status != 200:
self._logger.error("Please check your network configuration page: %s-%s", resp.status, resp.reason)
return False
except Exception as e:
except aiohttp.ClientError as e:
self._logger.error('Callback error: %s. Please check your network configuration page', e)
return False
return True
Expand All @@ -93,8 +95,9 @@ async def _send_task(self):
self.__changes = {}

try:
await self.send_to_jeedom(changes)
except Exception as e:
if not await self.send_to_jeedom(changes):
await self.__merge_dict(self.__changes,changes)
except aiohttp.ClientError as e:
if last_send_on_error:
self._logger.error("error during send: %s", e)
else:
Expand Down
2 changes: 1 addition & 1 deletion jeedomdaemon/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def api_key(self):

@property
def pid_filename(self):
return str(self._args.pid)
return str(self._args.pid)
17 changes: 10 additions & 7 deletions jeedomdaemon/base_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ def __init__(self,
) -> None:
self._config = config
self._config.parse()
self._listen_task = None
self._listen_task: asyncio.Task[None] | None = None
self._send_task: asyncio.Task[None] | None = None
self._loop = None
self._jeedom_publisher: Publisher | None = None
self._logger = logging.getLogger(__name__)
self.__log_level = Utils.convert_log_level(self._config.log_level)
self._on_start_cb = on_start_cb
Expand All @@ -47,14 +49,14 @@ def run(self):
Utils.write_pid(str(self._config.pid_filename))

asyncio.run(self.__run())
except Exception as e:
except Exception as e: # pylint: disable=broad-exception-caught
self._logger.error('Fatal error: %s', e)
finally:
self._logger.info("Shutdown")
try:
self._logger.debug("Removing PID file %s", self._config.pid_filename)
os.remove(self._config.pid_filename)
except:
except: # pylint: disable=bare-except
pass

self._logger.debug("Exit 0")
Expand Down Expand Up @@ -89,11 +91,12 @@ def stop(self):

tasks = [t for t in asyncio.all_tasks() if t is not asyncio.current_task()]
tasks = asyncio.all_tasks()
[task.cancel() for task in tasks]
self._logger.info("Cancelling %i outstanding tasks", len(tasks))
for task in tasks:
task.cancel()
try:
asyncio.gather(*tasks, return_exceptions=True)
except Exception as e:
except BaseException as e: # pylint: disable=broad-exception-caught
self._logger.warning("Some exception occured during cancellation: %s", e)

def __ask_exit(self, sig):
Expand All @@ -112,5 +115,5 @@ async def __on_socket_message(self, message):
if self._on_message_cb is not None:
await self._on_message_cb(message)

except Exception as e:
self._logger.error('Send command to demon error: %s', e)
except Exception as e: # pylint: disable=broad-exception-caught
self._logger.error('Send command to demon error: %s', e)

0 comments on commit 2493b67

Please sign in to comment.