in smart-mirror-full/extracted/device/script/src/agt/alexa_gadget.py [0:0]
def _on_bluetooth_data_received(self, data):
"""
Received bluetooth data.
"""
if not data:
return
# Parse the main message.
pb_msg = proto.Message()
try:
pb_msg.ParseFromString(data)
except:
logger.error('Error handling data: {}'.format(data.hex()))
return
# parse the directive
pb_directive = proto.Directive()
pb_directive.ParseFromString(pb_msg.payload)
namespace = pb_directive.header.namespace
name = pb_directive.header.name
proto_class = getattr(proto, name + 'Directive', None)
if proto_class and namespace == proto_class.DESCRIPTOR.GetOptions().Extensions[proto.namespace]:
pb_directive = proto_class()
pb_directive.ParseFromString(pb_msg.payload)
# call the callback.
try:
self.on_directive(pb_directive)
except:
logger.exception("Exception handling directive from Echo device")