xaal.lib 0.7.8__py3-none-any.whl → 0.7.10__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
xaal/lib/__init__.py CHANGED
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  # Load main class & modules.
4
2
 
5
3
 
@@ -8,7 +6,7 @@ from . import tools
8
6
  from . import bindings
9
7
  from . import aiohelpers as helpers
10
8
 
11
- from .core import Timer
9
+ from .core import Timer
12
10
 
13
11
  # sync engine
14
12
  from .engine import Engine
@@ -19,5 +17,5 @@ from .aioengine import AsyncEngine
19
17
  from .aionetwork import AsyncNetworkConnector
20
18
 
21
19
  from .devices import Device, Attribute, Attributes
22
- from .messages import Message,MessageFactory,MessageType
20
+ from .messages import Message, MessageFactory, MessageType, MessageAction
23
21
  from .exceptions import *
xaal/lib/aioengine.py CHANGED
@@ -36,7 +36,7 @@ class HookType(Enum):
36
36
  class Hook(object):
37
37
  __slots__ = ['type', 'func', 'args', 'kwargs']
38
38
 
39
- def __init__(self, type_:HookType, func: core.FuncT, *args, **kwargs):
39
+ def __init__(self, type_: HookType, func: core.FuncT, *args, **kwargs):
40
40
  # func has to be a callable, but it can be a coroutine or a function
41
41
  self.type = type_
42
42
  self.func = func
@@ -58,7 +58,8 @@ class AsyncEngine(core.EngineMixin):
58
58
  ]
59
59
 
60
60
  def __init__(
61
- self, address: str = config.address, port: int = config.port, hops: int = config.hops, key: bytes = config.key):
61
+ self, address: str = config.address, port: int = config.port, hops: int = config.hops, key: bytes = config.key
62
+ ):
62
63
  core.EngineMixin.__init__(self, address, port, hops, key)
63
64
 
64
65
  self.__txFifo = asyncio.Queue() # tx msg fifo
@@ -167,7 +168,7 @@ class AsyncEngine(core.EngineMixin):
167
168
 
168
169
  async def handle_action_request(self, msg: 'Message', target: 'Device'):
169
170
  if msg.action is None:
170
- return # should not happen, but pyright need this check
171
+ return # should not happen, but pyright need this check
171
172
 
172
173
  try:
173
174
  result = await run_action(msg, target)
@@ -250,7 +251,8 @@ class AsyncEngine(core.EngineMixin):
250
251
  self.new_task(self.receive_task(), name='RecvQ')
251
252
  self.new_task(self.send_task(), name='SendQ')
252
253
  self.new_task(self.timer_task(), name='Timers')
253
- self.new_task(console(locals()), name='Console')
254
+ if config.remote_console:
255
+ self.new_task(console(locals()), name='Console')
254
256
 
255
257
  def setup_alives_timer(self):
256
258
  # needed on stop-start sequence
@@ -259,7 +261,7 @@ class AsyncEngine(core.EngineMixin):
259
261
  # process alives every 10 seconds
260
262
  self.add_timer(self.process_alives, 10)
261
263
 
262
- async def stop(self): # pyright: ignore
264
+ async def stop(self): # pyright: ignore
263
265
  logger.info("Stopping engine")
264
266
  await self.run_hooks(HookType.stop)
265
267
  self.running_event.clear()
@@ -340,7 +342,7 @@ class AsyncEngine(core.EngineMixin):
340
342
  self.dump_hooks()
341
343
 
342
344
  def get_device(self, uuid: UUID) -> Optional['Device']:
343
- # TODO:Check if this method is usefull
345
+ # TODO:Check if this method is usefull
344
346
  for dev in self.devices:
345
347
  if dev.address == uuid:
346
348
  return dev
@@ -391,7 +393,8 @@ async def console(locals=locals(), port: Optional[int] = None):
391
393
  # let's find a free port if not specified
392
394
  def find_free_port():
393
395
  import socketserver
394
- with socketserver.TCPServer(('localhost', 0), None) as s: # pyright: ignore pyright reject the None here
396
+
397
+ with socketserver.TCPServer(('localhost', 0), None) as s: # pyright: ignore pyright reject the None here
395
398
  return s.server_address[1]
396
399
 
397
400
  port = find_free_port()
@@ -407,6 +410,8 @@ async def console(locals=locals(), port: Optional[int] = None):
407
410
  # start the console
408
411
  try:
409
412
  # debian with ipv6 disabled still state that localhost is ::1, which broke aioconsole
410
- await aioconsole.start_interactive_server(host="127.0.0.1", port=port, factory=factory, banner=banner) # pyright: ignore
413
+ await aioconsole.start_interactive_server(
414
+ host="127.0.0.1", port=port, factory=factory, banner=banner
415
+ ) # pyright: ignore
411
416
  except OSError:
412
417
  logger.warning("Unable to run console")
xaal/lib/config.py CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  # Default configuration
3
2
 
4
3
  import os
@@ -7,20 +6,23 @@ import binascii
7
6
  from configobj import ConfigObj
8
7
 
9
8
  # Default settings
10
- DEF_ADDR = '224.0.29.200'
9
+ DEF_ADDR = "224.0.29.200"
11
10
  DEF_PORT = 1236
12
11
  DEF_HOPS = 10
13
12
  DEF_ALIVE_TIMER = 100
14
13
  DEF_CIPHER_WINDOW = 60 * 2
15
14
  DEF_QUEUE_SIZE = 10
16
- DEF_LOG_LEVEL = 'DEBUG'
17
- DEF_LOG_PATH = '/var/log/xaal'
15
+ DEF_LOG_LEVEL = "DEBUG"
16
+ DEF_LOG_PATH = "/var/log/xaal"
17
+ DEF_REMOTE_CONSOLE = False
18
+
18
19
 
19
20
  STACK_VERSION = 7
20
21
 
22
+
21
23
  class Config:
22
24
  def __init__(self):
23
- self.conf_dir = os.environ.get('XAAL_CONF_DIR', os.path.expanduser("~/.xaal"))
25
+ self.conf_dir = os.environ.get("XAAL_CONF_DIR", os.path.expanduser("~/.xaal"))
24
26
  self.address = DEF_ADDR
25
27
  self.port = DEF_PORT
26
28
  self.hops = DEF_HOPS
@@ -29,10 +31,11 @@ class Config:
29
31
  self.queue_size = DEF_QUEUE_SIZE
30
32
  self.log_level = DEF_LOG_LEVEL
31
33
  self.log_path = DEF_LOG_PATH
34
+ self.remote_console = DEF_REMOTE_CONSOLE
32
35
  self.key = b''
33
36
  self.STACK_VERSION = STACK_VERSION
34
37
 
35
- def load(self, name='xaal.ini'):
38
+ def load(self, name="xaal.ini"):
36
39
  filename = os.path.join(self.conf_dir, name)
37
40
  if not os.path.isfile(filename):
38
41
  raise FileNotFoundError(f"Unable to load xAAL config file [{filename}]")
@@ -46,6 +49,8 @@ class Config:
46
49
  self.queue_size = self.safe_int(cfg.get('queue_size'), DEF_QUEUE_SIZE)
47
50
  self.log_level = self.safe_string(cfg.get('log_level'), DEF_LOG_LEVEL)
48
51
  self.log_path = self.safe_string(cfg.get('log_path'), DEF_LOG_PATH)
52
+ self.remote_console = self.safe_bool(cfg.get('remote_console'), DEF_REMOTE_CONSOLE)
53
+
49
54
  key = cfg.get('key', None)
50
55
  if key and type(key) is str:
51
56
  self.key = binascii.unhexlify(key.encode('utf-8'))
@@ -73,6 +78,14 @@ class Config:
73
78
  except (ValueError, TypeError):
74
79
  return default
75
80
 
81
+ @staticmethod
82
+ def safe_bool(value, default):
83
+ if value is None:
84
+ return default
85
+ if value.lower() == "true":
86
+ return True
87
+ return False
88
+
76
89
 
77
90
  config = Config()
78
91
  try:
xaal/lib/core.py CHANGED
@@ -56,7 +56,7 @@ class EngineMixin(object):
56
56
  __slots__ = ['devices', 'timers', 'subscribers', 'msg_filter', '_attributesChange', 'network', 'msg_factory']
57
57
 
58
58
  def __init__(self, address: str, port: int, hops: int, key: bytes):
59
- self.devices:list[Device] = [] # list of devices / use (un)register_devices()
59
+ self.devices: list[Device] = [] # list of devices / use (un)register_devices()
60
60
  self.timers: list[Timer] = [] # functions to call periodic
61
61
  self.subscribers: list[SubFuncT] = [] # message receive workflow
62
62
  self.msg_filter = None # message filter
@@ -134,7 +134,7 @@ class EngineMixin(object):
134
134
  self.queue_msg(msg)
135
135
  dev.update_alive()
136
136
 
137
- def send_is_alive(self, dev: 'Device', targets: list = [ALIVE_ADDR,], dev_types: list = ["any.any", ] ):
137
+ def send_is_alive(self, dev: 'Device', targets: list = [ALIVE_ADDR], dev_types: list = ["any.any"]):
138
138
  """Send a is_alive message, w/ dev_types filtering"""
139
139
  body = {'dev_types': dev_types}
140
140
  self.send_request(dev, targets, MessageAction.IS_ALIVE.value, body)
xaal/lib/devices.py CHANGED
@@ -21,7 +21,7 @@
21
21
  import logging
22
22
  import time
23
23
  import typing
24
- from typing import Any, Optional, Union, Callable, Awaitable
24
+ from typing import Any, Optional, Union, Callable, Awaitable, Dict
25
25
 
26
26
  from tabulate import tabulate
27
27
 
@@ -133,7 +133,7 @@ class Device(object):
133
133
  self.next_alive = 0
134
134
  # Default attributes & methods
135
135
  self.__attributes = Attributes()
136
- self.methods: dict[str, MethodT] = {
136
+ self.methods: Dict[str, MethodT] = {
137
137
  'get_attributes': self._get_attributes,
138
138
  'get_description': self._get_description,
139
139
  }
@@ -225,7 +225,7 @@ class Device(object):
225
225
  if name in self.methods:
226
226
  del self.methods[name]
227
227
 
228
- def get_methods(self) -> dict[str, MethodT]:
228
+ def get_methods(self) -> Dict[str, MethodT]:
229
229
  return self.methods
230
230
 
231
231
  def update_alive(self):
xaal/lib/engine.py CHANGED
@@ -25,8 +25,6 @@ import typing
25
25
  from enum import Enum
26
26
  from typing import Optional
27
27
 
28
-
29
-
30
28
  from .config import config
31
29
  from . import core
32
30
  from .exceptions import CallbackError, MessageParserError, XAALError
@@ -135,11 +133,11 @@ class Engine(core.EngineMixin):
135
133
  * error returned on the xAAL bus
136
134
  """
137
135
  if msg.action is None:
138
- return # should not happen, but pyright need this check
136
+ return # should not happen, but pyright need this check
139
137
 
140
138
  try:
141
139
  result = run_action(msg, target)
142
- if result:
140
+ if result is not None:
143
141
  self.send_reply(dev=target, targets=[msg.source], action=msg.action, body=result)
144
142
  except CallbackError as e:
145
143
  self.send_error(target, e.code, e.description)
xaal/lib/messages.py CHANGED
@@ -342,8 +342,9 @@ def build_nonce(data: tuple) -> bytes:
342
342
 
343
343
  def build_timestamp() -> tuple:
344
344
  """Return array [seconds since epoch, microseconds since last seconds] Time = UTC+0000"""
345
- epoch = datetime.datetime.fromtimestamp(0, datetime.UTC)
346
- timestamp = datetime.datetime.now(datetime.UTC) - epoch
345
+ utc = datetime.timezone.utc
346
+ epoch = datetime.datetime.fromtimestamp(0, utc)
347
+ timestamp = datetime.datetime.now(utc) - epoch
347
348
  return (int(timestamp.total_seconds()), int(timestamp.microseconds))
348
349
 
349
350
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xaal.lib
3
- Version: 0.7.8
3
+ Version: 0.7.10
4
4
  Summary: Official Python stack for xAAL protocol
5
5
  Author-email: Jerome Kerdreux <Jerome.Kerdreux@imt-atlantique.fr>
6
6
  License: GPL License
@@ -0,0 +1,22 @@
1
+ xaal/__init__.py,sha256=jv2YF__bseklT3OWEzlqJ5qE24c4aWd5F4r0TTjOrWQ,65
2
+ xaal/lib/__init__.py,sha256=yI2lG7uSbedjp1h2FCdcAUGzkyuJxYyNbK13SHvwNew,491
3
+ xaal/lib/__main__.py,sha256=xsVqqoIh3UeJIXxeexSfmGSUP4YxUcibdZExjEzk4lE,30
4
+ xaal/lib/aioengine.py,sha256=BHCDfr3yVurQj3ePFHyDoBpqqyMuppxLD7OvG6IWgkI,14029
5
+ xaal/lib/aiohelpers.py,sha256=O1oQX8XHxuvCL1ual509chjoR52AwV_ZGqeAbSlvFrE,1010
6
+ xaal/lib/aionetwork.py,sha256=WSYwxwEHJaQDlfVocX8ow2tAtssWcH9LxPAazx4Qx_o,2547
7
+ xaal/lib/bindings.py,sha256=V77bFfeVFj0GyGuwH8b4k7qSyA7zApZYJ8QTjq_3DwI,2140
8
+ xaal/lib/cbor.py,sha256=XX0zgTU0uwQD9QXctGLT4lEISohi1whMUdyWKMevH8c,1647
9
+ xaal/lib/config.py,sha256=KR28xC8NGyGjvFD9QcAoWfwyf7xcXDEP7aSenNmaRzM,3019
10
+ xaal/lib/core.py,sha256=IBTrCCZhBKKYOuZWImxETbLZ5_upH5MRoIKKBXYEXvU,11982
11
+ xaal/lib/devices.py,sha256=CaUH3i_xTQD0W63fW93glI-Ck2_YVvMpdn8y7BqQqzw,10696
12
+ xaal/lib/engine.py,sha256=oFiBIma5M6Qv0W2wMmWdyCRuu7BwqR-DRUvqWfajh-A,8141
13
+ xaal/lib/exceptions.py,sha256=4cKKkDDcZIPyVrLv3Q19apbn_pIqDGqXb1s1d2sZnpI,573
14
+ xaal/lib/helpers.py,sha256=lPtEwP82Ssd9igmxJGq2UzmPVCyRBMHULBBVyAH4Blg,2827
15
+ xaal/lib/messages.py,sha256=FpdIZ5flzUfgXaVVptv_tirvq5jL__mjUGimExwK9Z0,12388
16
+ xaal/lib/network.py,sha256=oHpyHXkFT31RS6UKMZstC33dgC_sTtYKzfpgugY26oU,3277
17
+ xaal/lib/test.py,sha256=GTjIwdqRupdqO4lNhAnc4iH0azfCCMN9BEpJpgAUors,2944
18
+ xaal/lib/tools.py,sha256=Py_RUmLcOVjYDcm7muQ6jZPJLdOKzBfOKstX73K4Jqg,4157
19
+ xaal.lib-0.7.10.dist-info/METADATA,sha256=wnOQJjes_62vU63PL8hKCKsskwSJr8TbBtHY9XZj-IU,4351
20
+ xaal.lib-0.7.10.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
+ xaal.lib-0.7.10.dist-info/top_level.txt,sha256=UZ2WDkN02ztkh1OrsjrW8Kmj4n3WqC0BQxaEYOYfWa0,5
22
+ xaal.lib-0.7.10.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- xaal/__init__.py,sha256=jv2YF__bseklT3OWEzlqJ5qE24c4aWd5F4r0TTjOrWQ,65
2
- xaal/lib/__init__.py,sha256=xsA9c2uhC2799fM6P5hK3aQcuvoKE6FCPYQ3WbJOfZ8,477
3
- xaal/lib/__main__.py,sha256=xsVqqoIh3UeJIXxeexSfmGSUP4YxUcibdZExjEzk4lE,30
4
- xaal/lib/aioengine.py,sha256=3l5wCRV9ZySfJOpKxDD_yO81NtL1v246mMveR28q9ms,13959
5
- xaal/lib/aiohelpers.py,sha256=O1oQX8XHxuvCL1ual509chjoR52AwV_ZGqeAbSlvFrE,1010
6
- xaal/lib/aionetwork.py,sha256=WSYwxwEHJaQDlfVocX8ow2tAtssWcH9LxPAazx4Qx_o,2547
7
- xaal/lib/bindings.py,sha256=V77bFfeVFj0GyGuwH8b4k7qSyA7zApZYJ8QTjq_3DwI,2140
8
- xaal/lib/cbor.py,sha256=XX0zgTU0uwQD9QXctGLT4lEISohi1whMUdyWKMevH8c,1647
9
- xaal/lib/config.py,sha256=Lspz3YAjSl2KhKKHW_Ns79rBNujOr5kGmwRxuMaH4pA,2661
10
- xaal/lib/core.py,sha256=WUdG1k7H589FpVbTkotHX574KiSYISZ622eWy3Af3B0,11985
11
- xaal/lib/devices.py,sha256=__wUD-pbpKrNj85_n4nEyexsQamv4CWqUz1Yfz0N5FM,10690
12
- xaal/lib/engine.py,sha256=mZI9nxW1aLAsbRCJM3QhEeQnmyyeISznJQl0-8S24Ig,8130
13
- xaal/lib/exceptions.py,sha256=4cKKkDDcZIPyVrLv3Q19apbn_pIqDGqXb1s1d2sZnpI,573
14
- xaal/lib/helpers.py,sha256=lPtEwP82Ssd9igmxJGq2UzmPVCyRBMHULBBVyAH4Blg,2827
15
- xaal/lib/messages.py,sha256=cezaFBtdbyQzKwGNh6dDLhmgn5ZkST7u2lAC49Xr8JE,12374
16
- xaal/lib/network.py,sha256=oHpyHXkFT31RS6UKMZstC33dgC_sTtYKzfpgugY26oU,3277
17
- xaal/lib/test.py,sha256=GTjIwdqRupdqO4lNhAnc4iH0azfCCMN9BEpJpgAUors,2944
18
- xaal/lib/tools.py,sha256=Py_RUmLcOVjYDcm7muQ6jZPJLdOKzBfOKstX73K4Jqg,4157
19
- xaal.lib-0.7.8.dist-info/METADATA,sha256=SgmY8n4kXUyIqRg8gLCJ-NCxwVxeYomlQChEzupZ-S0,4350
20
- xaal.lib-0.7.8.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
21
- xaal.lib-0.7.8.dist-info/top_level.txt,sha256=UZ2WDkN02ztkh1OrsjrW8Kmj4n3WqC0BQxaEYOYfWa0,5
22
- xaal.lib-0.7.8.dist-info/RECORD,,