Skip to content

Commit

Permalink
Handle top-level event types
Browse files Browse the repository at this point in the history
  • Loading branch information
jtc42 committed May 5, 2020
1 parent 463ce8c commit bb35494
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/labthings/server/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@


class Event:
# Some event types are formatted slightly differently
magic_types = {"propertyStatus", "actionStatus"}

def __init__(self, name, schema=None):
self.name = name
self.schema = schema
Expand All @@ -10,9 +13,9 @@ def __init__(self, name, schema=None):

def emit(self, data):
response = {
"messageType": self.name,
"messageType": self.name if self.name in Event.magic_types else "event",
"timestamp": datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
"data": data,
"data": data if self.name in Event.magic_types else {self.name: data},
} # TODO: Format data with schema
self.events.append(response)
return response
1 change: 1 addition & 0 deletions src/labthings/server/labthing.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def init_app(self, app):

# Create base events
self.add_event("propertyStatus")
self.add_event("actionStatus")
self.add_event("logging")

def _create_base_routes(self):
Expand Down

0 comments on commit bb35494

Please sign in to comment.