xair-api 2.3.1__py3-none-any.whl → 2.3.2__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.
xair_api/errors.py CHANGED
@@ -1,2 +1,14 @@
1
1
  class XAirRemoteError(Exception):
2
2
  """Base error class for XAIR Remote."""
3
+
4
+
5
+ class XAirRemoteConnectionTimeoutError(XAirRemoteError):
6
+ """Exception raised when a connection attempt times out"""
7
+
8
+ def __init__(self, ip, port):
9
+ self.ip = ip
10
+ self.port = port
11
+
12
+ super().__init__(
13
+ f"Timeout attempting to connect to mixer at {self.ip}:{self.port}"
14
+ )
xair_api/util.py CHANGED
@@ -1,6 +1,35 @@
1
1
  import functools
2
+ import time
2
3
  from math import exp, log
3
4
 
5
+ from .errors import XAirRemoteConnectionTimeoutError
6
+
7
+
8
+ def timeout(func):
9
+ """
10
+ Times out the validate_connection function once time elapsed exceeds remote.connect_timeout.
11
+ """
12
+
13
+ @functools.wraps(func)
14
+ def wrapper(*args, **kwargs):
15
+ remote, *_ = args
16
+
17
+ err = None
18
+ start = time.time()
19
+ while time.time() < start + remote.connect_timeout:
20
+ try:
21
+ func(*args, **kwargs)
22
+ remote.logger.debug(f"login time: {round(time.time() - start, 2)}")
23
+ err = None
24
+ break
25
+ except XAirRemoteConnectionTimeoutError as e:
26
+ err = e
27
+ continue
28
+ if err:
29
+ raise err
30
+
31
+ return wrapper
32
+
4
33
 
5
34
  def lin_get(min, max, val):
6
35
  return min + (max - min) * val
xair_api/xair.py CHANGED
@@ -14,11 +14,11 @@ from pythonosc.dispatcher import Dispatcher
14
14
  from pythonosc.osc_message_builder import OscMessageBuilder
15
15
  from pythonosc.osc_server import BlockingOSCUDPServer
16
16
 
17
- from . import adapter, kinds
17
+ from . import adapter, kinds, util
18
18
  from .bus import Bus
19
19
  from .config import Config
20
20
  from .dca import DCA
21
- from .errors import XAirRemoteError
21
+ from .errors import XAirRemoteConnectionTimeoutError, XAirRemoteError
22
22
  from .fx import FX, FXSend
23
23
  from .kinds import KindMap
24
24
  from .lr import LR
@@ -47,8 +47,6 @@ class OSCClientServer(BlockingOSCUDPServer):
47
47
  class XAirRemote(abc.ABC):
48
48
  """Handles the communication with the mixer via the OSC protocol"""
49
49
 
50
- _CONNECT_TIMEOUT = 0.5
51
-
52
50
  _info_response = []
53
51
 
54
52
  def __init__(self, **kwargs):
@@ -57,6 +55,7 @@ class XAirRemote(abc.ABC):
57
55
  self.xair_ip = kwargs["ip"] or self._ip_from_toml()
58
56
  self.xair_port = kwargs["port"]
59
57
  self._delay = kwargs["delay"]
58
+ self.connect_timeout = kwargs["connect_timeout"]
60
59
  self.logger = logger.getChild(self.__class__.__name__)
61
60
  if not self.xair_ip:
62
61
  raise XAirRemoteError("No valid ip detected")
@@ -74,13 +73,10 @@ class XAirRemote(abc.ABC):
74
73
  conn = tomllib.load(f)
75
74
  return conn["connection"].get("ip")
76
75
 
76
+ @util.timeout
77
77
  def validate_connection(self):
78
- self.send("/xinfo")
79
- time.sleep(self._CONNECT_TIMEOUT)
80
- if not self.info_response:
81
- raise XAirRemoteError(
82
- "Failed to setup OSC connection to mixer. Please check for correct ip address."
83
- )
78
+ if not self.query("/xinfo"):
79
+ raise XAirRemoteConnectionTimeoutError(self.xair_ip, self.xair_port)
84
80
  self.logger.info(
85
81
  f"Successfully connected to {self.info_response[2]} at {self.info_response[0]}."
86
82
  )
@@ -117,7 +113,12 @@ def _make_remote(kind: KindMap) -> XAirRemote:
117
113
  """
118
114
 
119
115
  def init_x32(self, *args, **kwargs):
120
- defaultkwargs = {"ip": None, "port": 10023, "delay": 0.02}
116
+ defaultkwargs = {
117
+ "ip": None,
118
+ "port": 10023,
119
+ "delay": 0.02,
120
+ "connect_timeout": 2,
121
+ }
121
122
  kwargs = defaultkwargs | kwargs
122
123
  XAirRemote.__init__(self, *args, **kwargs)
123
124
  self.kind = kind
@@ -135,7 +136,12 @@ def _make_remote(kind: KindMap) -> XAirRemote:
135
136
  self.config = Config.make(self)
136
137
 
137
138
  def init_xair(self, *args, **kwargs):
138
- defaultkwargs = {"ip": None, "port": 10024, "delay": 0.02}
139
+ defaultkwargs = {
140
+ "ip": None,
141
+ "port": 10024,
142
+ "delay": 0.02,
143
+ "connect_timeout": 2,
144
+ }
139
145
  kwargs = defaultkwargs | kwargs
140
146
  XAirRemote.__init__(self, *args, **kwargs)
141
147
  self.kind = kind
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xair-api
3
- Version: 2.3.1
3
+ Version: 2.3.2
4
4
  Summary: Remote control Behringer X-Air | Midas MR mixers through OSC
5
5
  Home-page: https://github.com/onyx-and-iris/xair-api-python
6
6
  License: MIT
@@ -73,7 +73,7 @@ if __name__ == "__main__":
73
73
  main()
74
74
  ```
75
75
 
76
- #### `xair_api.connect(kind_id, ip=ip, delay=delay)`
76
+ #### `xair_api.connect(kind_id, ip=ip, delay=0.02, connect_timeout=2)`
77
77
 
78
78
  Currently the following devices are supported:
79
79
 
@@ -90,6 +90,7 @@ The following keyword arguments may be passed:
90
90
  - `port`: mixer port, defaults to 10023 for x32 and 10024 for xair
91
91
  - `delay`: a delay between each command (applies to the getters). Defaults to 20ms.
92
92
  - a note about delay, stability may rely on network connection. For wired connections the delay can be safely reduced.
93
+ - `connect_timeout`: amount of time to wait for a validated connection. Defaults to 2s.
93
94
 
94
95
  ## API
95
96
 
@@ -335,6 +336,14 @@ for example:
335
336
  print(mixer.query("/ch/01/mix/on"))
336
337
  ```
337
338
 
339
+ ### Errors
340
+
341
+ - `errors.XAirRemoteError`: Base error class for XAIR Remote.
342
+ - `errors.XAirRemoteConnectionTimeoutError`:Exception raised when a connection attempt times out.
343
+ - The following attributes are available:
344
+ - `ip`: IP of the mixer.
345
+ - `port`: Port of the mixer.
346
+
338
347
  ### `Tests`
339
348
 
340
349
  Unplug any expensive equipment before running tests.
@@ -3,7 +3,7 @@ xair_api/adapter.py,sha256=icQXeqrYu6iWOJbke6zXdOzxyhAV__dXKrCnuDbZAUU,797
3
3
  xair_api/bus.py,sha256=digswx5ApbLCpF6R7_8OqfvnJ8C9JIFpe8MFxKXbSB0,1771
4
4
  xair_api/config.py,sha256=ditmhP770trYIu7eouw4pU3BgOtXwOB8dearYJbhSuw,5853
5
5
  xair_api/dca.py,sha256=C-wyBqeAi0qr1qrOKefyIWsJwI8ebs2iV83Q2iC67-k,1443
6
- xair_api/errors.py,sha256=RAqGQ3gndR9l8c_RfEBKC0tMsa5_n8F7o3X7ppVHfL8,80
6
+ xair_api/errors.py,sha256=rfFmAW6QitHe0iB56M48He-qsbvDaKe1_AN_j4-9oUA,411
7
7
  xair_api/fx.py,sha256=AzjgpJSHDCWwWRGCWxeGwwsm8jcxl3fJykprk9cwSUM,1811
8
8
  xair_api/kinds.py,sha256=ulJJhLpiUuOw5Ir7Q3CQbmAKrd33xq8CIHpAFc5zEdw,1119
9
9
  xair_api/lr.py,sha256=WL5YnDeLeJPxIK5OdTqZQ3s6UEfQ3-onz99OEdi0-mE,1788
@@ -11,10 +11,10 @@ xair_api/meta.py,sha256=iUWPSP4QcWMW6gyLc5SGDJ49pKZgJrHzFphtL6OFptE,1564
11
11
  xair_api/rtn.py,sha256=lOTGSkxsYpc4usIba-reZSRmfa-7JIr_FTThSw6BdLY,3177
12
12
  xair_api/shared.py,sha256=ABVTgx9sIH9zZLJLKeZBrhdMXj-WGNuggxrqjn8oa3M,19171
13
13
  xair_api/strip.py,sha256=pAFX0Ssq1kC9BghGJhd6ShJ0on16DbkWoickH0jA-Jg,2082
14
- xair_api/util.py,sha256=VYgSWxKXnvD3tu564wbr5PTdODNrmGNnsZErER5hY3I,1485
15
- xair_api/xair.py,sha256=966mt1rYbjCtC82vtnKIpbrRYAGFnvgz8ctHxTvDL1Y,6261
16
- xair_api-2.3.1.dist-info/entry_points.txt,sha256=p2vlpkx3x9BZ3Mslqg2ngV3g-mdqwB14oEltOqi8kgg,105
17
- xair_api-2.3.1.dist-info/LICENSE,sha256=m2fbtv9II-iQqimTd4zjgynL5vuEqGXauLSDJZycYIo,1124
18
- xair_api-2.3.1.dist-info/METADATA,sha256=llkWczr78xaVVyGZ-5LjnzpFLxXp8IePPszpjrers_M,8483
19
- xair_api-2.3.1.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
20
- xair_api-2.3.1.dist-info/RECORD,,
14
+ xair_api/util.py,sha256=Rd2eGhqIjFe29s-0ffQGzs9p5lXsfCRJ91i6BPEVzxE,2263
15
+ xair_api/xair.py,sha256=60ZAZVj0dWmVfcedFtB_rEbv6fnyb-7nP-Z1ltAeqUs,6384
16
+ xair_api-2.3.2.dist-info/entry_points.txt,sha256=hlKDU0C0XSGDitHXAvt6YQfmI99p3eJBaoQqEQhpH2U,126
17
+ xair_api-2.3.2.dist-info/LICENSE,sha256=m2fbtv9II-iQqimTd4zjgynL5vuEqGXauLSDJZycYIo,1124
18
+ xair_api-2.3.2.dist-info/METADATA,sha256=OhG5fjrYkW_wVbEFE6yIbaup5Owe0rz2e1scbLIX2rg,8868
19
+ xair_api-2.3.2.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
20
+ xair_api-2.3.2.dist-info/RECORD,,
@@ -1,4 +1,5 @@
1
1
  [console_scripts]
2
+ all=scripts:test_all
2
3
  obs=scripts:ex_obs
3
4
  sends=scripts:ex_sends
4
5
  x32=scripts:test_x32