]> git.aero2k.de Git - sirius.git/commitdiff
Add and handle DeviceCommandResponse.
authorTom Hunger <tehunger@gmail.com>
Thu, 15 Jan 2015 16:50:19 +0000 (16:50 +0000)
committerTom Hunger <tehunger@gmail.com>
Thu, 15 Jan 2015 16:50:19 +0000 (16:50 +0000)
sirius/coding/decoders.py
sirius/protocol/messages.py
sirius/protocol/protocol_loop.py

index a08001707ef951b0d8a948c8894b014cbaebd718..9f14be2e710e581fe2368dd4b98e2f4ece53e750 100644 (file)
@@ -69,6 +69,9 @@ def decode_message(data):
     elif data['type'] == 'BridgeCommandResponse':
         return _decode_bridge_command_response(data)
 
+    elif data['type'] == 'DeviceCommandResponse':
+        return _decode_device_command_response(data)
+
     elif data['type'] == 'DeviceEvent':
         return _decode_device_event(data)
 
@@ -257,3 +260,15 @@ def _decode_bridge_command_response(data):
         timestamp=data['timestamp'],
         return_code=data['return_code'],
     )
+
+def _decode_device_command_response(data):
+    """Decodes a DeviceCommandResponse.
+
+    :param data: A python dictionary, as decoded from json.
+    """
+    return messages.DeviceCommandResponse(
+        bridge_address=data['bridge_address'],
+        command_id=data['command_id'],
+        timestamp=data['timestamp'],
+        return_code=data['return_code'],
+    )
index c0c4df8dae132237152a0992cab5d29e47a1b17b..8fe1577b944fca73a92151fd0ac9789b1cb00fd8 100644 (file)
@@ -55,6 +55,13 @@ BridgeCommandResponse = namedtuple('BridgeCommandResponse', [
     'timestamp',
 ])
 
+DeviceCommandResponse = namedtuple('DeviceCommandResponse', [
+    'bridge_address',
+    'command_id',
+    'return_code',
+    'timestamp',
+])
+
 SetDeliveryAndPrint = namedtuple('SetDeliveryAndPrint', [
     'device_address',
     'pixels', # 384 pixels wide
index 2325c3653b315def9549c653e7d887ba72ad9a6e..a689d8166c2c1a4252d02e4d8d4dc031a1410300 100644 (file)
@@ -197,6 +197,11 @@ def _accept_step(x, bridge_state):
             logger.error('Unexpected response (command_id not known) %r', x)
             return
 
+    elif type(x) == messages.DeviceCommandResponse:
+        if x.command_id not in bridge_state.pending_commands:
+            logger.error('Unexpected response (command_id not known) %r', x)
+            return
+
         # TODO: some commands need special handling. E.g. what happens
         # on invalid claim codes? How do we communicate send-errors or
         # timeouts back to the user?