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)
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'],
+ )
'timestamp',
])
+DeviceCommandResponse = namedtuple('DeviceCommandResponse', [
+ 'bridge_address',
+ 'command_id',
+ 'return_code',
+ 'timestamp',
+])
+
SetDeliveryAndPrint = namedtuple('SetDeliveryAndPrint', [
'device_address',
'pixels', # 384 pixels wide
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?