Skip to content

Commit

Permalink
add connected flag to monome.Device
Browse files Browse the repository at this point in the history
  • Loading branch information
artfwo committed Feb 1, 2024
1 parent 24dabcc commit 43bb4ec
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions monome.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ def __init__(self, prefix='monome'):
self.add_handler('/sys/disconnect', self._on_sys_disconnect)
self.add_handler('/sys/{id,size,host,port,prefix,rotation}', self._on_sys_info)

self.connected = False
self.transport = None

self.prefix = prefix

self.ready_event = Event()
self.disconnect_event = Event()
self._unset_info_properties()

def _unset_info_properties(self):
self._reset_info_properties()

def _reset_info_properties(self):
self.id = None
self.width = None
self.height = None
Expand All @@ -78,6 +82,7 @@ def _on_sys_info(self, addr, path, *args):
self.rotation = args[0]

if self._info_properties_set():
self.connected = True
self.ready_event.dispatch()

def connection_made(self, transport):
Expand Down Expand Up @@ -107,9 +112,9 @@ async def connect(self, host, port, loop=None):

def disconnect(self):
self.disconnect_event.dispatch()
self._unset_info_properties()
self._reset_info_properties()
self.transport.close()

self.connected = False

class Grid(Device):
def __init__(self, prefix='monome'):
Expand Down

0 comments on commit 43bb4ec

Please sign in to comment.