Skip to content

Commit

Permalink
split start off from the connect procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
cereal2nd committed Dec 13, 2024
1 parent b0817ba commit 8124e6a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/load_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
async def main(connect_str: str, address: str):
velbus = Velbus(dsn=connect_str, one_address=address)
await velbus.connect()
await velbus.start()
for mod in (velbus.get_modules()).values():
print(mod)
print("")
Expand Down
1 change: 1 addition & 0 deletions examples/load_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def main(connect_str: str):
# velbus = Velbus("/dev/ttyAMA0")
velbus = Velbus(connect_str)
await velbus.connect()
await velbus.start()
for mod in (velbus.get_modules()).values():
print(mod)
print("")
Expand Down
1 change: 1 addition & 0 deletions examples/read_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
async def main(connect_str: str):
velbus = Velbus(connect_str)
await velbus.connect()
await velbus.start()
for mod in (velbus.get_modules()).values():
print(mod)
print("")
Expand Down
15 changes: 6 additions & 9 deletions velbusaio/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,9 @@ async def stop(self) -> None:
self._auto_reconnect = False
self._protocol.close()

async def connect(self, test_connect: bool = False) -> None:
async def connect(self) -> None:
"""Connect to the bus and load all the data."""
await self._handler.read_protocol_data()
auth = None
# connect to the bus
if ":" in self._dsn:
# tcp/ip combination
Expand All @@ -157,8 +156,6 @@ async def connect(self, test_connect: bool = False) -> None:
ctx = ssl._create_unverified_context()
else:
ctx = None
if parts.username:
auth = parts.username
try:
(
_transport,
Expand Down Expand Up @@ -190,12 +187,12 @@ async def connect(self, test_connect: bool = False) -> None:
)
except (FileNotFoundError, serial.SerialException) as err:
raise VelbusConnectionFailed from err
if test_connect:
return
# if auth is required send the auth key
if auth:
await self._protocol.write_auth_key(auth)

async def start(self) -> None:
# if auth is required send the auth key
parts = urlparse(self._dsn)
if parts.username:
await self._protocol.write_auth_key(parts.username)
# scan the bus
await self._handler.scan()

Expand Down

0 comments on commit 8124e6a

Please sign in to comment.