Skip to content

Commit

Permalink
implement connection listener.
Browse files Browse the repository at this point in the history
  • Loading branch information
amit lissack committed Oct 23, 2021
1 parent 11e6e0c commit 54206f1
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
from typing import Sequence, Set, Callable, List, Awaitable

from opentrons.drivers.rpi_drivers.types import USBPort
from opentrons.hardware_control.emulation.module_server.client import ModuleServerClient
from opentrons.hardware_control.emulation.module_server.models import Message
from opentrons.hardware_control.emulation.module_server.server import log
Expand Down Expand Up @@ -28,14 +29,34 @@ def __init__(self, client: ModuleServerClient, notify_method: NotifyMethod) -> N
self._notify_method = notify_method

async def run(self) -> None:
""""""
"""Run the listener."""
while True:
m = await self._client.read()
await self.message_to_notify(message=m, notify_method=self._notify_method)

@staticmethod
async def message_to_notify(message: Message, notify_method: NotifyMethod) -> None:
await notify_method([], [])
"""Call callback with results of message.
Args:
message: Message object from module server
notify_method: callback method
Returns:
None
"""
connections = [
ModuleAtPort(
port=c.url,
name=c.module_type,
usb_port=USBPort(name=c.identifier, sub_names=[]),
)
for c in message.connections
]
if message.status == "connected" or message.status == "dump":
await notify_method(connections, [])
elif message.status == "disconnected":
await notify_method([], connections)


async def wait_emulators(
Expand Down

0 comments on commit 54206f1

Please sign in to comment.