def _handle_frame_failure(self, message_type, destination, aps_frame, message_tag, status, message): try: send_fut, reply_fut = self._pending.pop(message_tag) send_fut.set_exception(DeliveryError("Message send failure: %s" % (status, ))) reply_fut.cancel() except KeyError: LOGGER.warning("Unexpected message send failure") except asyncio.futures.InvalidStateError as exc: LOGGER.debug("Invalid state on future - probably duplicate response: %s", exc)
def request(self, nwk, aps_frame, data, timeout=10): seq = aps_frame.sequence assert seq not in self._pending send_fut = asyncio.Future() reply_fut = asyncio.Future() self._pending[seq] = (send_fut, reply_fut) v = yield from self._ezsp.sendUnicast(self.direct, nwk, aps_frame, seq, data) if v[0] != 0: self._pending.pop(seq) send_fut.cancel() reply_fut.cancel() raise DeliveryError("Message send failure %s" % (v[0], )) # Wait for messageSentHandler message v = yield from send_fut # Wait for reply v = yield from asyncio.wait_for(reply_fut, timeout) return v