def _receive_data(self, sender: str, data: bytes): logger.debug(f"Current state: {self.state}, received from '{sender}': {hexlify(bytes(data))}") self._packet = Packet.from_bytes(data) logger.debug(f"Parsed response packet: {self._packet}") assert self.state.name.startswith("Requested"), "unexpected packet" self.loop.call_soon_threadsafe(self._event.set())
def receive_data(self, sender, data): logger.debug( f"State: {self.state}, received from '{sender}': {hexlify(bytes(data))}" ) packet = Packet.from_bytes(data) logger.debug(f"Parsed: {packet}") if self.state == BandState.RequestedLinkParams: if packet.service_id != DeviceConfig.id and packet.command_id != DeviceConfig.LinkParams.id: raise RuntimeError("unexpected packet") self.parse_link_params(packet.command) elif self.state == BandState.RequestedAuthentication: if packet.service_id != DeviceConfig.id and packet.command_id != DeviceConfig.Auth.id: raise RuntimeError("unexpected packet") self.parse_authentication(packet.command) elif self.state == BandState.RequestedBondParams: if packet.service_id != DeviceConfig.id and packet.command_id != DeviceConfig.BondParams.id: raise RuntimeError("unexpected packet") self.parse_bond_params(packet.command) elif self.state == BandState.RequestedBond: if packet.service_id != DeviceConfig.id and packet.command_id != DeviceConfig.Bond.id: raise RuntimeError("unexpected packet") self.parse_bond(packet.command) self._event.set()