<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def stop_sync(self):
 """Safely stop this BLED112 instance without leaving it in a weird state."""


        # Disconnect connected device
        if self.connected:
            self.disconnect_sync(self._connection_handle)

        # Disable advertising
        self.set_advertising(False)
        # Stop the baBLE interface
        self.bable.stop()

        self.actions.queue.clear()