Skip to content

Commit a53c220

Browse files
authored
Revert "Remove async get_factory. (#990)"
This reverts commit b396c39.
1 parent b396c39 commit a53c220

File tree

8 files changed

+44
-8
lines changed

8 files changed

+44
-8
lines changed

pymodbus/client/asynchronous/factory/serial.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ def async_io_factory(port=None, framer=None, **kwargs):
3535
future.result()
3636

3737
return loop, client
38+
39+
40+
def get_factory():
41+
"""Get protocol factory.
42+
43+
:return: new factory
44+
"""
45+
return async_io_factory

pymodbus/client/asynchronous/factory/tcp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):
3838
client = future.result()
3939

4040
return loop, client
41+
42+
43+
def get_factory():
44+
"""Get protocol factory.
45+
46+
:return: new factory
47+
"""
48+
return async_io_factory

pymodbus/client/asynchronous/factory/tls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ def async_io_factory(
5151
client = future.result()
5252

5353
return loop, client
54+
55+
56+
def get_factory():
57+
"""Get protocol factory.
58+
59+
:return: protocol object
60+
"""
61+
return async_io_factory

pymodbus/client/asynchronous/factory/udp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,11 @@ def async_io_factory(host="127.0.0.1", port=Defaults.Port, **kwargs):
3535
client = client.result()
3636

3737
return loop, client
38+
39+
40+
def get_factory():
41+
"""Get protocol factory.
42+
43+
:return: new factory
44+
"""
45+
return async_io_factory

pymodbus/client/asynchronous/serial.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""SERIAL communication."""
22
import logging
33

4-
from pymodbus.client.asynchronous.factory.serial import async_io_factory
4+
from pymodbus.client.asynchronous.factory.serial import get_factory
55
from pymodbus.exceptions import ParameterException
66
from pymodbus.factory import ClientDecoder
77
from pymodbus.transaction import (
@@ -58,6 +58,7 @@ def __new__(cls, method, port, **kwargs):
5858
:param kwargs:
5959
:return:
6060
"""
61+
factory_class = get_factory()
6162
framer = cls._framer(method)
62-
yieldable = async_io_factory(framer=framer, port=port, **kwargs)
63+
yieldable = factory_class(framer=framer, port=port, **kwargs)
6364
return yieldable

pymodbus/client/asynchronous/tcp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""TCP communication."""
22
import logging
33

4-
from pymodbus.client.asynchronous.factory.tcp import async_io_factory
4+
from pymodbus.client.asynchronous.factory.tcp import get_factory
55
from pymodbus.constants import Defaults
66

77
_logger = logging.getLogger(__name__)
@@ -33,7 +33,8 @@ def __new__(
3333
:param kwargs: Other extra args specific to Backend being used
3434
:return:
3535
"""
36-
yieldable = async_io_factory(
36+
factory_class = get_factory()
37+
yieldable = factory_class(
3738
host=host,
3839
port=port,
3940
framer=framer,

pymodbus/client/asynchronous/tls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""TLS communication."""
22
import logging
33

4-
from pymodbus.client.asynchronous.factory.tls import async_io_factory
4+
from pymodbus.client.asynchronous.factory.tls import get_factory
55
from pymodbus.constants import Defaults
66
from pymodbus.factory import ClientDecoder
77
from pymodbus.transaction import ModbusTlsFramer
@@ -44,7 +44,8 @@ def __new__(
4444
:return:
4545
"""
4646
framer = framer or ModbusTlsFramer(ClientDecoder())
47-
yieldable = async_io_factory(
47+
factory_class = get_factory()
48+
yieldable = factory_class(
4849
host=host,
4950
port=port,
5051
sslctx=sslctx,

pymodbus/client/asynchronous/udp.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""UDP communication."""
22
import logging
33

4-
from pymodbus.client.asynchronous.factory.udp import async_io_factory
4+
from pymodbus.client.asynchronous.factory.udp import get_factory
55
from pymodbus.constants import Defaults
66

77
_logger = logging.getLogger(__name__)
@@ -33,7 +33,8 @@ def __new__(
3333
:param kwargs: Other extra args specific to Backend being used
3434
:return:
3535
"""
36-
yieldable = async_io_factory(
36+
factory_class = get_factory()
37+
yieldable = factory_class(
3738
host=host,
3839
port=port,
3940
framer=framer,

0 commit comments

Comments
 (0)