]> git.aero2k.de Git - sirius.git/commitdiff
final, probably broken, commit before starting a bit of code organisation
authorMatt Webb <matt@interconnected.org>
Wed, 24 Sep 2014 17:09:22 +0000 (18:09 +0100)
committerMatt Webb <matt@interconnected.org>
Wed, 24 Sep 2014 17:09:22 +0000 (18:09 +0100)
app/events.py

index f29ada86b44fedaa60fc53f3b17db0f8b9bc4091..6c39ebcb13ce8bd41604a45c439d005c93c8d48f 100644 (file)
@@ -1,5 +1,8 @@
 from . import commands
 from .payload import DeviceEventPayload
+from . import claiming
+
+from datetime import datetime
 
 # process_event should...
 # - break apart the event
@@ -9,6 +12,24 @@ from .payload import DeviceEventPayload
 # all of this is happening within a try:except: in the event loop,
 # so don't be afraid to crash out
 
+class PendingClaims(object):
+    
+    def __init__(self):
+        self.encryption_keys = {} # hardware_address_xor: encryption_key
+    
+    def add_claim_code(self, claim_code):
+        hardware_address_xor, encryption_key = claiming.process_claim_code(claim_code)
+        #@TODO handle exception
+        
+        self.encryption_keys[hardware_address_xor] = encryption_key
+    
+    def key_for_address(self, device_address):
+        hardware_address_xor = claiming.make_hardware_address_xor(device_address)
+        return self.encryption_keys.get(hardware_address_xor, None)
+
+pending_claims = PendingClaims()
+
+
 class EventProcessingException(Exception): pass
 
 # @TODO command_sender shouldn't be passed in here, and of course it
@@ -21,7 +42,8 @@ def process_event(ws, event, command_sender):
         # types: heartbeat, did_print, did_power_on
         # see device_event.py in hubcode
         payload = DeviceEventPayload.from_base64(event['binary_payload'])
-        print "DeviceEvent: %r" % payload['name']
+        timestamp = datetime.fromtimestamp(event['timestamp'])
+        print "DeviceEvent: %r at %s" % (payload['name'], timestamp.isoformat())
         if payload['name'] == 'heartbeat':
             if command_sender.did_send_image is False:
                 print "Sending set_delivery_and_print"
@@ -33,7 +55,8 @@ def process_event(ws, event, command_sender):
         # change the command delivery map. there is also power_on,
         # encryption_key_required [4 events are all I can find]
         event_name = event['json_payload']['name']
-        print "BridgeEvent: %r" % event_name
+        timestamp = datetime.fromtimestamp(event['timestamp'])
+        print "BridgeEvent: %r at %s" % (event_name, timestamp.isoformat())
         if event_name == 'device_connect':
             command_sender.add_device(event['json_payload']['device_address'], ws)
         elif event_name == 'device_disconnect':